Making A Find Button

  • Thread starter Thread starter Strow
  • Start date Start date
Option Explicit
Option Compare Database
Private Sub cmdSearch_Click()
Dim strSearch As String
Dim strReportName As String
Dim strCriteria As String
strSearch = ""

If Nz(Me.txtfNameSeach, "") <> "" Then
strSearch = "firstname = '" & Me.txtfNameSeach & "'"
End If
If Nz(Me.txtlNameSeach, "") <> "" Then
If strSearch <> "" Then
strSearch = strSearch & " AND "
End If
strSearch = strSearch & "lastname = '" & Me.txtlNameSeach & "'"
End If
If Nz(Me.txtphoneSeach, "") <> "" Then
If strSearch <> "" Then
strSearch = strSearch & " AND "
End If
strSearch = strSearch & "Telephone = '" & Me.txtphoneSeach & "'"
End If

If strSearch <> "" Then
DoCmd.OpenForm "Clients", , , strSearch
DoEvents
If Forms!clients.Recordset.EOF Then
MsgBox "No Records Found"
'DoCmd.Close acForm, "Clients"
End If
Else
Me.FilterOn = False
DoCmd.Close acForm, "Find"
End If
End Sub

this is the code for my find form, and i want it so that after the
serach is done, the find box closes and if there are no records i want
my clients form to requery and have all the records in it instead of it
becoming blank because no records
 
Het is zò dat Strow formuleerde :

If strSearch <> "" Then
DoCmd.OpenForm "Clients", , , strSearch
DoEvents
If Forms!clients.Recordset.EOF Then
MsgBox "No Records Found"
'DoCmd.Close acForm, "Clients"
End If
Else
Me.FilterOn = False
DoCmd.Close acForm, "Find"
End If
End Sub

this is the code for my find form, and i want it so that after the
serach is done, the find box closes and if there are no records i want
my clients form to requery and have all the records in it instead of it
becoming blank because no records

OK, well, you're almost there then. But, the Me keyword is always about
the current form. The current form is the form "Find" and you want to
remove the filter from the form "Clients"
So, change that to
Forms![Clients].Filteron = false
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top