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
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