Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help need with query 2

Status
Not open for further replies.

neoice

Programmer
Feb 15, 2003
110
GB
Hello,

I wonder if somebody could help me out here as i am getting confused. i want to search my access DB based on surname and forename. It works great if i search on surname but I just get muddled up when trying to combine both the surname and the forename fields.

Below is the code i use to search by surname:

Set rs1 = db.OpenRecordset("SELECT * FROM query1 " & "WHERE surname = " & "'" & txtsurname.Text & "'", dbOpenDynaset)

lblparent.Caption = rs1("parent")
lblhouse.Caption = rs1("house_no")
etc..


thanks in advance
neil

 
Try
Code:
Set rs1 = db.OpenRecordset( _
"SELECT * " & _
"FROM query1 " & _
"WHERE     SurName  = '" & txtsurname.Text & "' " _
"      AND ForeName = '" & txtForeName.Text & "' ", dbOpenDynaset)
 
Set rs1 = db.OpenRecordset(
"SELECT * FROM query1 " &
" WHERE surname = '" & txtsurname.Text & "'" &
" AND forename = '" & txtforename & "'"
, dbOpenDynaset)

Note the space before the AND - a common mistake is to leave it out when concatenating strings in this way.
 
neoice, did you not find either of these post, Valuable Post?

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top