SQL syntax error - no idea why!!

branston

Registered User.
Local time
Today, 13:51
Joined
Apr 29, 2009
Messages
372
Hi, The code below throws up an error every time it is run:

strSQL = ("SELECT TblPcrMain WHERE TblPcrMain.ProjectNo = '" & strProj & "' AND TblPcrMain.PcrNo =" & intPcr)

The error is "Syntax error (missing operator) in..."
I have checked and checked it and i cant see anythign wrong with it. Im starting to think im going crazy. I have taught myself access, so i might be missing something vital so any help would be greatly appreciated before my computer gets flung across the room!

Thank you
 
That line compiles fine for me. Do you get the error when you try to execute the sql or just when the variable is assigned?
 
I just realized you are missing a vital piece if you actually try to execute this sql - It should be 'Select * From TblPcrMain Where .......". This would return all fields in the table. If you didn't want all the fields you would list them as in 'Select Name, Address, Zip from TblPcrMain Where .......'.
 
the next few lines of code are:

strSQL = ("SELECT TblPcrMain WHERE TblPcrMain.ProjectNo = '" & strProj & "' AND TblPcrMain.PcrNo =" & intPcr)
Set myDB = CurrentDb()
Set myRS = myDB.OpenRecordset(strSQL)

so i guess it might be getting the error when it tried to open the recordset?
 
ah, just saw your 2nd post... I tried select from but it didnt like that, but i forgot about the *, ill give it a go now. Thank you!
 
wonderfull... cant believe ive just spent about 3 hours looking for missing " & 's!!

Thank you!
 

Users who are viewing this thread

Back
Top Bottom