I've recently been rewriting the code for a search function I had, so I don't have to replicate the code on every single form I create, but can call it using a sub on a module. However, I can't get findfirst to work properly. Currently, my code is set up like this:
___________________________________________
Private Sub SearchButtonClick()
SearchFor Me, [Field].Name, Me.SearchBox.Text
End Sub
______________________________________________
This bit of code is present in every form that currently has search functionality. The [Field] here is variable, depending on what's being searched for.
In the module portion, the code looks like this:
_______________________________________________
Public Sub SearchFor (frmCurr, varf, valf)
If IsNumeric(valf) 'Check if the value for the field is an integer
frmCurr.RecordsetClone.FindFirst frmCurr(varf) & "=" & valf
Else
'String version of the above code
End If
If frmCurr.RecordsetClone.NoMatch = False Then
frmCurr.Bookmark = frmCurr.RecordsetClone.Bookmark
End If
_____________________________
I've used Message Boxes to spit out both the name and the value of frmCurr(varf) so I know it's properly passing and looking up the field name. However, the Findfirst method either fails to return anything, or gives me an error.
I'm separating the module into frmCurr, which means form current. varf and valf are for "variable field" and "value field" to get the field name and the value we want to search the field for. The idea being that I can just pass the field to search and item to search for, and the module can handle it to reduce code duplication across the database (since I'll be handing this off in a month or two, and the team I'm handing it off to doesn't have too much Acccess experience- I'd rather make it as easy to learn as possible.)
What am I doing wrong?
___________________________________________
Private Sub SearchButtonClick()
SearchFor Me, [Field].Name, Me.SearchBox.Text
End Sub
______________________________________________
This bit of code is present in every form that currently has search functionality. The [Field] here is variable, depending on what's being searched for.
In the module portion, the code looks like this:
_______________________________________________
Public Sub SearchFor (frmCurr, varf, valf)
If IsNumeric(valf) 'Check if the value for the field is an integer
frmCurr.RecordsetClone.FindFirst frmCurr(varf) & "=" & valf
Else
'String version of the above code
End If
If frmCurr.RecordsetClone.NoMatch = False Then
frmCurr.Bookmark = frmCurr.RecordsetClone.Bookmark
End If
_____________________________
I've used Message Boxes to spit out both the name and the value of frmCurr(varf) so I know it's properly passing and looking up the field name. However, the Findfirst method either fails to return anything, or gives me an error.
I'm separating the module into frmCurr, which means form current. varf and valf are for "variable field" and "value field" to get the field name and the value we want to search the field for. The idea being that I can just pass the field to search and item to search for, and the module can handle it to reduce code duplication across the database (since I'll be handing this off in a month or two, and the team I'm handing it off to doesn't have too much Acccess experience- I'd rather make it as easy to learn as possible.)
What am I doing wrong?