Input box Search problem

Eljefegeneo

Still trying to learn
Local time
Yesterday, 20:34
Joined
Jan 10, 2011
Messages
902
Input box Search problem
I have been using the following to find a record in my frmMain using an Input Box:
Private Sub cmdClientIdSearch_Click()
'Searches for Client by ID number
Dim rs As Object
Dim strCriteria As String

strCriteria = InputBox("Please enter Client ID" & vbCr & "Do not type leading zeros")

If strCriteria > "" Then
Set rs = Me.RecordsetClone
With rs
.FindFirst "[ClientID] Like '" & Val(strCriteria) & "*'"
If .NoMatch Then
MsgBox "Sorry, no match was found.", vbExclamation, "Not Found"
Else
Me.Bookmark = .Bookmark
End If
End With
Set rs = Nothing
End If
End Sub

It works great if I run it from a command button from frmMain. But, if frmMain is open and I run it from a command button on my switchboard, I get the following error message:
Run Time error 7951. You entered an expression that has an invalid reference to the Recordset Clone Property. I tried inserting a command to open frmMain in the first line, even before the two Dim statements, but I get the same result. Maybe someone could tell me where I am miscoding. Thanks.
 
Thanks, but it seems it is in a format that I cannot open.
 
Replace Me. with Forms!yourFormName.Form.RecordsetClone
 
Thank you. The code works fine now. But what I do not understand is why it wouldn't work if I simply had the code open the form from the switchboard and then run my original code. As I said before, my original code worked without the modification when I executed it from a command button on the form.

Just a small point but would help me to understand the mysteries of Access VBA better.

Thanks again.
 
When you use Me. it represents the current Object. So when it is run from the form, Me. refers to the form name so it will work, when it goes to the Switchboard Me. will represent the Switchboard and switchboard will not have a recordsource thus no recordset. Since this code is used outside the main form, the detailed path information to the form's recordsource is required than just simply using Me
 
Thanks. Another small step in learning! Much appreciated.
 

Users who are viewing this thread

Back
Top Bottom