Strow beweerde :
Option Compare Database
Private Sub cmdSearch_Click()
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
Dim strSearch As String
strSearch = ""
If Nz(Me.txtfNameSeach, "") <> "" Then
strSearch = "firstname = '" & Me.txtfNameSeach & "'"
End If
If Nz(Me.txtlNameSeach, "") <> "" Then
If strSearch <> "" Then
strSeach = strSeach & " AND "
End If
strSearch = strSearch & "lastname = '" & Me.txtlNameSeach & "'"
End If
If Nz(Me.txtphoneSeach, "") <> "" Then
If strSearch <> "" Then
strSeach = strSeach & " AND "
End If
strSearch = strSearch & "Telephone = '" & Me.txtphoneSeach & "'"
End If
If strSearch <> "" Then
Me.Filter = strSearch
Me.FilterOn = True
If Me.Recordset.EOF Then
MsgBox ("No Records Found")
End If
Else
End If
End Sub
You can delete the following two lines, you're not creating a recordset
here.
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
Now, from what I've read in previous messages, you have two forms, one
showing the results, one with the search-stuff. I call the results form
frmResult in the code below and the searchform frmSearch.
Remove the last lines and replace them with these :
If strSearch <> "" Then
docmd.openform "frmResults",,,strSearch
'give access some time to show the form
doevents
'then check the recordset of the form to see if any records are
there
If forms!frmResults.recordset.eof Then
MsgBox "No Records Found"
'Close the resultsform again
docmd.close acform, "frmResults"
End If
Else
'The search is showing results, close the searchform
docmd.close acform, frmSearch
End If
End Sub
I think this should do the trick... You are now opening the resultsform
with a filtercondition. It will show you only records that correspond
to the filter. You might want to set the allowadditions to false to
prevent the user adding records.
If no records match the filtercondition, the messagebox comes up and
the form (frmResults) is closed.