Hi everybody!
I have a form with three unbound text boxes that are to be used as three different search functions. I have control buttons next to each text box that open a report based on parameters collected from the text boxes. I'd like the user to be able to just hit the enter key after entering their search parameters in the text box, and I've got a code that kinda works except it only works once. After "enter" is hit the first time, any subsequent search will return ALL records. Oddly enough, this doesn't affect the control buttons. They seem to still return only records matching the terms entered into the text box. The form is named "School Information Search". Here's what the form looks like:
Using the first text box and control button as an example, if you type the name of a school and click the "Search by School Name" control button, a macro runs to open a report. The report's linked query uses the following criteria under the field that is searched:
Like "*" & [Forms]![School Information Search]![SchoolNameSearchBar] & "*"
The macro resets the text box by SetProperty --> Value --> [left blank]. This button always works. No issues on subsequent searches.
If one types a search term and hits enter, the report is opened using the following code:
Private Sub SchoolNameSearchBar_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
DoCmd.OpenReport "School Search by Name", acViewReport
End If
End Sub
The first time I attempted a search using this code it worked. But every subsequent attempt has opened a report showing ALL the records. I have no idea what is happening here.
I have an inkling that because the enter key moves to a new line in the text box, the report may be collecting its parameters using the blank new line. Does this make sense? Any possible fixes?
Thanks.
EDIT: Apparently it's not because of the new line in the text box. I just changed "Enter Key Behaviour" to Default and it still returns all records in the report.
I have a form with three unbound text boxes that are to be used as three different search functions. I have control buttons next to each text box that open a report based on parameters collected from the text boxes. I'd like the user to be able to just hit the enter key after entering their search parameters in the text box, and I've got a code that kinda works except it only works once. After "enter" is hit the first time, any subsequent search will return ALL records. Oddly enough, this doesn't affect the control buttons. They seem to still return only records matching the terms entered into the text box. The form is named "School Information Search". Here's what the form looks like:
Using the first text box and control button as an example, if you type the name of a school and click the "Search by School Name" control button, a macro runs to open a report. The report's linked query uses the following criteria under the field that is searched:
Like "*" & [Forms]![School Information Search]![SchoolNameSearchBar] & "*"
The macro resets the text box by SetProperty --> Value --> [left blank]. This button always works. No issues on subsequent searches.
If one types a search term and hits enter, the report is opened using the following code:
Private Sub SchoolNameSearchBar_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
DoCmd.OpenReport "School Search by Name", acViewReport
End If
End Sub
The first time I attempted a search using this code it worked. But every subsequent attempt has opened a report showing ALL the records. I have no idea what is happening here.
I have an inkling that because the enter key moves to a new line in the text box, the report may be collecting its parameters using the blank new line. Does this make sense? Any possible fixes?
Thanks.
EDIT: Apparently it's not because of the new line in the text box. I just changed "Enter Key Behaviour" to Default and it still returns all records in the report.