Searching

T

tmaxwell

I have a Database Named Contacts, I need to be able to enter a name or
address any of the fields I could search on. I am not sure this is the
correct code for doing this, but I need help . Please



Private Sub Button197_Click()
On Error GoTo Err_Button197_Click

Dim strWhere As String
If Not IsNull(Me.TxtSearch) Then
strWhere = "QRY_NAMES = """ & Me.TxtSearch & """"
End If
DoCmd.OpenForm "QRY_NAMES, , , strWhere"


Rem Err_Button197_Click:
Rem MsgBox "Error finding record: " & Error$
Rem RetVal = False
Rem Resume Next
Rem MsgBox Error$
Rem Resume Exit_Button197_Click

Exit_Button197_Click:
Exit Sub



End Sub
 
S

Steve Sanford

Here is an example of code to open a form with criteria. You will need to
change "YourFormName" to the name of your form. I hope you do not have a
field named "QRY_NAMES" -AND- and forme named "QRY_NAMES".

Try this:
'------------------------------
Private Sub Command197_Click()
On Error GoTo Err_Command197_Click

Dim stDocName As String
Dim strWhere As String

stDocName = "YourFormName"

stLinkCriteria = "[QRY_NAMES] = """ & Me.TxtSearch & """"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command197_Click:
Exit Sub

Err_Command197_Click:
MsgBox Err.Description
Resume Exit_Command197_Click

End Sub
'------------------------------

HTH
 

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