Connecting Tech Pros Worldwide Forums | Help | Site Map

Search function Query

Newbie
 
Join Date: May 2007
Posts: 1
#1: May 4 '07
HI All,
I m trying to write an SQL query in VBA to a sql string. It will be used for a search form. I want the query to evaluate multiple text boxes filled in by the user. For example, they are fields like street name, street type, house number.
If the user inputs say Street name and Street type , 'abc st', the query should evaluate both the fields entered by the user and search for it and provide results which correspond to the entered fields , eg: should return the output as 'abc st', but i ve the written the query which would give me all the occurences for abc and the st and not the combination of it.

Following is my query:
strSQL = "SELECT E.* " & _
"FROM E " & _
"WHERE E.M='" & Me.txtmirn.Value & "' " & _
"OR E.Site='" & Me.txtcity.Value & "' " & _
"OR E.Ga='" & Me.txtgas.Value & "' " & _
"OR E.Site='" & Me.txtdpi.Value & "' " & _
"ORDER BY E.M;"

I would appreciate if anyone can tell mewhere i m going wrong?
Cheers
Aj

pks00's Avatar
Expert
 
Join Date: Oct 2006
Posts: 281
#2: May 4 '07

re: Search function Query


Wotcha Aj, its cos u got OR in there instead of AND.
Try changing it to that and see what happens
JConsulting's Avatar
Expert
 
Join Date: Apr 2007
Location: Houston
Posts: 601
#3: May 6 '07

re: Search function Query


strSQL = "SELECT E.* FROM E WHERE E.M='" & nz(Me.txtmirn,'*') & "' And" & _
" E.Site='" & nz(Me.txtcity,'*') & "' And E.Ga='" & nz(Me.txtgas,'*') & "' And" & _
" E.Site='" & nz(Me.txtdpi,'*') & "' ORDER BY E.M;"
Reply