Textbox search exact match question

hardrock

Registered User.
Local time
Today, 16:50
Joined
Apr 5, 2007
Messages
166
Hi all, looking at the code below, i enter a string in "BDAY" textbox and hit search. If will find all records with part of the string in the CARD column. How do i modify it to find an exact string match. thanks



Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.

If Not IsNull(Me.brake) Then
strWhere = strWhere & "([CARD] Like ""*" & Me.BDAY & "*"") AND "
End If


'Chop off the trailing " AND ", and use the string as the form's Filter.
'If the string has more than 5 characters (a trailng " AND ") to remove.

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)

'Apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
 
remove the "like" from your criteria
 
re:

Thats what i thought mate but its the syntax that im struggling on. Can you show me how to write the line correctly without the "like"
 
I believe its

Code:
strWhere= "[Card] = '" & Me.Bday & "'"
 
It compiles ok, but the result it gives is not what im after!

Basically BDAY can be 5 digits long i.e 100000 if 100000 exists in column CARD in my table then i want to display the filtered record on my form. If no exact match is found then i want to show a msgbox. "No record found"
cheers
 
Figured it out in the end! must be in this format to work

If Not IsNull(Me.BDAY) Then
strWhere = strWhere & "([CARD] = " & Me.BDAY & ") AND "
End If


A right bugga!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom