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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA strSQL syntax error, please help 1

Status
Not open for further replies.

knifey

Technical User
Nov 14, 2006
180
GB
Hi,
I have an Excel spreadsheet containing patient names and DOB's that I want to match to our Access database.
I'm pretty new to Access VBA and was wiondering if anyone can offer any advice on where I'm going wrong.
The error I'm getting when I paste into Access SQL view is
'Syntax error (missing operater) in query expression.'

VBA code:
strSQL = "SELECT * FROM [Patient Basic details] WHERE Patient Basic details.[LastName] ='" & lastNameVal & "' And Patient Basic details.[FirstName] ='" & firstNameVal & "' And Patient Basic details.[Birthdate] = #" & colPVal & "# Or Patient Basic details.[LastName] ='" & lastNameVal & "' And Left(Patient Basic details.[FirstName], 1) ='" & firstInitialVal & "' And Patient Basic details.[Birthdate] = #" & colPVal & "#;"

'It falls over here with a runtime error 3075 (syntax error)
Set rsCheck = db.OpenRecordset(strSQL)

Immediate window ?strSQL result:
?strSQL
SELECT * FROM [Patient Basic details] WHERE Patient Basic details.[LastName] ='JAMA' And Patient Basic details.[FirstName] ='HINDA' And Patient Basic details.[Birthdate] = #03/08/1977# Or Patient Basic details.[LastName] ='JAMA' And Left(Patient Basic details.[FirstName], 1) ='H' And Patient Basic details.[Birthdate] = #03/08/1977#;

Where am I going wrong? Please help.
Thanks,
Knifey
 
Use brackets !
WHERE [!][[/!]Patient Basic details[!]][/!].

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV,
I feel like a bit of doughnut for asking the question now!
Cheers,
Roy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top