converting filter from wild card to extact match

dj_mix

Registered User.
Local time
Today, 14:15
Joined
Aug 30, 2006
Messages
39
I have a search box and it looks up project id number.
the orginal code works but filters anything with that particular number.

I like to adjust the filter to equal to the number enter.

ex,, I enter 22 , i get records with 622, 223, etc
I want it to be only 22

I can't seem to figure this out.. here's te code

Private Sub txtSearchString_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

LSearchString = txtSearchString

'Filter results based on search string
LSQL = "select * from [Projects - Active]"
LSQL = LSQL & " where ID LIKE '*" & LSearchString & "*'"

Form_frmSearch_sub.RecordSource = LSQL

lblTitle.Caption = "Project ID: Filtered by '" & LSearchString & "'"

'Clear search string
txtSearchString = ""

End Sub
 
Change

LSQL = LSQL & " where ID LIKE '*" & LSearchString & "*'"

to

LSQL = LSQL & " where ID = '" & LSearchString & "'"
 
grnzbra said:
Change

LSQL = LSQL & " where ID LIKE '*" & LSearchString & "*'"

to

LSQL = LSQL & " where ID = '" & LSearchString & "'"

Just tried that I get a error

Run-time error '2001':
You cancel the previous operation

any idea what the error is ?
Thanx
 
Try adding to the beginning of the sub

On error goto errhandler.

Then, at the end enter


goto ExSub
errhandler:
msgbox err.number & " " & err.description
ExSub:


That will give you a messge box that tells you what the 2001 error is.
 
grnzbra said:
Try adding to the beginning of the sub

On error goto errhandler.

Then, at the end enter


goto ExSub
errhandler:
msgbox err.number & " " & err.description
ExSub:


That will give you a messge box that tells you what the 2001 error is.


says 2001 You cancel the previous operation

I appreciate the help...
 
I'm not sure what that error means but if it doens't help you, you might try
setting a break point at the

Form_frmSearch_sub.RecordSource = LSQL

line and then enter

?LSQL

in the immediate window to see just what the SQL statement looks like.
 
Ok I got it to work Thanx for the help .. I lead me to the right direction

LSearchString = txtSearchString

'Filter results based on search string
LSQL = "select * from [Projects - Active]"
LSQL = LSQL & " where [ID] = " & LSearchString & ""

Form_frmSearch_sub.RecordSource = LSQL

lblTitle.Caption = "Project ID: Filtered by '" & LSearchString & "'"

'Clear search string
txtSearchString = ""

End Sub


fixed LSQL = LSQL & " where [ID] = " & LSearchString & ""
 
Last edited:

Users who are viewing this thread

Back
Top Bottom