How to clear search bar text when closing form

独自空忆成欢 提交于 2020-07-23 07:22:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!