Find changes

R

rob peterson

I have a form called client-form. All records are stored by clientID (ABCD,
etc).

I added a command button for find. When I click it, I see field "look in".
That has my client-form and clientID. If it is clientID, it will work.

Sometimes when I click it it shows client-form (grayed out) and will not
work. Is there a better way to search for a record from a form?

(Here is the code generated by the button wizard:)

Private Sub findclientID_Click()
On Error GoTo Err_findclientID_Click


Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_findclientID_Click:
Exit Sub

Err_findclientID_Click:
MsgBox Err.Description
Resume Exit_findclientID_Click

End Sub
 
R

Ron Hinds

rob peterson said:
I have a form called client-form. All records are stored by clientID (ABCD,
etc).

I added a command button for find. When I click it, I see field "look in".
That has my client-form and clientID. If it is clientID, it will work.

Sometimes when I click it it shows client-form (grayed out) and will not
work. Is there a better way to search for a record from a form?

(Here is the code generated by the button wizard:)

Private Sub findclientID_Click()
On Error GoTo Err_findclientID_Click


Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_findclientID_Click:
Exit Sub

Err_findclientID_Click:
MsgBox Err.Description
Resume Exit_findclientID_Click

End Sub

Private Sub findclientID_Click()
On Error GoTo Err_findclientID_Click

Dim rs As Recordset
Dim strFind As String
Dim strBookmark As String

Set rs = Me.RecordsetClone

strFind = InputBox("Enter Client ID", "Client ID")

rs.FindFirst "ClientID=" & strFind

Me.Bookmark = rs.Bookmark

Exit_findclientID_Click:
Exit Sub

Err_findclientID_Click:
MsgBox Err.Description
Resume Exit_findclientID_Click

End Sub
 
R

rob peterson

thanks Ron.
very helpful.
rob

Ron Hinds said:
Private Sub findclientID_Click()
On Error GoTo Err_findclientID_Click

Dim rs As Recordset
Dim strFind As String
Dim strBookmark As String

Set rs = Me.RecordsetClone

strFind = InputBox("Enter Client ID", "Client ID")

rs.FindFirst "ClientID=" & strFind

Me.Bookmark = rs.Bookmark

Exit_findclientID_Click:
Exit Sub

Err_findclientID_Click:
MsgBox Err.Description
Resume Exit_findclientID_Click

End Sub
 
R

rob peterson

Question:
Code seemed to make sense to me. I copied it into click event. I get a
compile error: Method or data member not found on the rs.FindFirst
statement. ???

I am looking up "Client ID" and I spell it that way. (including in the
FindFirst statement). Any ideas?

Thanks.
Rob
 
J

J. Goddard

Try putting square brackets around "Client ID": [Client ID]

rs.FindFirst "[Client ID] =" & strFind

If Client ID is not numeric, you need:

rs.FindFirst "[Client ID]= '" & strFind & "'"

HTH

John
 
R

Ron Hinds

Yes - you're probably using ADO and the example I gave was for DAO. Instead
of FindFist, use rs.Find:

rs.Find "[Client ID]=" & strFind

As another poster pointed out, if your Client ID is a text field, you'll
need the single quote character like so:

rs.Find "[Client ID]='" & strFind & "'"
 

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