问题
I have a MainMenu with a search bar and two buttons. Button1 opens MainForm, Subform1, and Subform2 in VIEW only mode, filtered to the SchoolID typed into the unbound search bar.
My question is: When the user returns to the MainMenu by clicking my CloseFormOpenMainMenu button , how can I clear what is typed into the MainMenu search bar and clear the filter?
Here is my code on the MainMenu:
Private Sub Button1_Click()
Dim txtSearchBar As String
Dim Cancel As Integer
On Error GoTo ErrorBEDSIDSearch
DoCmd.OpenForm "MainForm", , , "SchoolID = " & ("""" & Me.txtSearchBar.Value
& """"), acFormReadOnly
Exit Sub
End Sub
Here is my code on the MainForm:
Private Sub CloseFormOpenMainMenu_Click()
DoCmd.Close
DoCmd.OpenForm "frmMainMenu"
End Sub
If it helps, I have the "Filter On Load" property = No and the "Filter" property is blank.
回答1:
You can use the following code to clear the textbox from the other form:
Forms("MainMenu").txtSearchBar.Value = Null
Implemented:
Private Sub CloseFormOpenMainMenu_Click()
DoCmd.Close
DoCmd.OpenForm "frmMainMenu"
Forms("MainMenu").txtSearchBar.Value = Null
End Sub
来源:https://stackoverflow.com/questions/49197533/how-to-clear-search-bar-text-when-closing-form