S
Steve
Good Morning,
I am working on creating a search form and I got the
following code from someone. It looks like it should work
but when it opens the results form it pulls up all of the
records. Any help would be greatly appreciated.
Private Sub cmdSearch_Click()
Dim sFilter As String
On Error GoTo cmdSearch_ClickERR
If txtfirstname = vbNullString Or IsNull(txtfirstname)
Then
Call MsgBox("Please enter a First Name..", vbOKOnly
+ vbInformation, "Search")
Exit Sub
End If
DoCmd.OpenForm "SearchResults"
sFilter = "First Name Like'" & txtfirstname
Form_SearchResults.Filter = sFilter
Form_SearchResults.FilterOn = True
If Form_SearchResults.RecordsetClone.RecordCount < 1
Then
Call MsgBox("No records found...", vbOKOnly +
vbInformation, "Search")
DoCmd.Close acForm, "SearchResults"
Exit Sub
End If
cmdSearch_ClickEXIT:
'Do any clean up here..
sFilter = vbNullString
Exit Sub
cmdSearch_ClickERR:
'Place your custom error handling code here..
Resume cmdSearch_ClickEXIT
End Sub
Thanks,
Steve
I am working on creating a search form and I got the
following code from someone. It looks like it should work
but when it opens the results form it pulls up all of the
records. Any help would be greatly appreciated.
Private Sub cmdSearch_Click()
Dim sFilter As String
On Error GoTo cmdSearch_ClickERR
If txtfirstname = vbNullString Or IsNull(txtfirstname)
Then
Call MsgBox("Please enter a First Name..", vbOKOnly
+ vbInformation, "Search")
Exit Sub
End If
DoCmd.OpenForm "SearchResults"
sFilter = "First Name Like'" & txtfirstname
Form_SearchResults.Filter = sFilter
Form_SearchResults.FilterOn = True
If Form_SearchResults.RecordsetClone.RecordCount < 1
Then
Call MsgBox("No records found...", vbOKOnly +
vbInformation, "Search")
DoCmd.Close acForm, "SearchResults"
Exit Sub
End If
cmdSearch_ClickEXIT:
'Do any clean up here..
sFilter = vbNullString
Exit Sub
cmdSearch_ClickERR:
'Place your custom error handling code here..
Resume cmdSearch_ClickEXIT
End Sub
Thanks,
Steve