I know this is an old dog but it still has a bite
In the code below, sStr can be a string or a "number"
If it is a number then findfirst returns not rs.nomatch
If sStr is a string that is exactly the same as the field value then success.
If sStr is not exactly the same as the field value then the result is always "rs.nomatch".
I.e sStr = "Genus". Field = "Genus mis-match".
I would like it to return all fields which include "Genus"
I have tried every combination of string concatenation I can think of, and some that AI came up with, to no avail.
I'm sure the solution is simple, but as of now, it is beyond me.
As always, any help is greatly appreciated.
John
In the code below, sStr can be a string or a "number"
If it is a number then findfirst returns not rs.nomatch
If sStr is a string that is exactly the same as the field value then success.
If sStr is not exactly the same as the field value then the result is always "rs.nomatch".
I.e sStr = "Genus". Field = "Genus mis-match".
I would like it to return all fields which include "Genus"
I have tried every combination of string concatenation I can think of, and some that AI came up with, to no avail.
Rich (BB code):
rs.findfirst "[" & sField & "] like '*" & sStr & "*'"
I'm sure the solution is simple, but as of now, it is beyond me.
Code:
Public Sub Find_Disc(frm As Form, sStr As String, sField as string)
Dim rs As Recordset
Set rs = frm.RecordsetClone
If Val(sStr) > 0 Then
rs.FindFirst sField & "= " & sStr 'This works with a numeric input
Else
rs.FindFirst sField & "= '" & sStr & "'" 'This works if the input is the same as the field value.
sStr = "*" & sStr & "*"
If rs.NoMatch Then rs.FindFirst "sField Like 'sStr'" 'This does not work.
End If
if not rs.nomatch then
frm.Bookmark = rs.Bookmark
FocusIt frm, sField
end if
Cleanup:
Set rs = Nothing
Set frm = Nothing
end sub
As always, any help is greatly appreciated.
John