Search/ Find Data Using Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that is setup with user data. I would like
to create a search button that will allow me to search on
different criteria such as user last name, company name.
What is the code to create a search/ find button that will
allow me to do this. I am trying to use the
DoCmd.FindRecord but am not having much success.
 
Hi ...

Try this .. Hope this helps ..

Click event for the Search button
In this code 'Search" is the name of the command button ..

On Error GoTo Err_Search_Click
Set db = Nothing
Set rst = Nothing
Set db = CurrentDb()

If IsNull(textboxname.Value) Then
strSQL = "SELECT * FROM [tablename] ORDER BY [fieldname];"
Else
strSQL = "SELECT * FROM [tablename] Where [field name in table] = '" &
Me![field name in the form] & "' "
End If

Set rst = db.OpenRecordset(strSQL)
Set formname.Form.Recordset = rst
formname.Requery

Exit_Search_Click:
Exit Sub

Err_Search_Click:
MsgBox Err.Description
Resume Exit_Search_Click


Praveen Manne
 
Back
Top