Search/ Find Data Using Form

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.
 
P

Praveen Manne

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
 

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

Top