Problem Using Query in VBA

mikewood1980

Registered User.
Local time
Today, 11:23
Joined
May 14, 2008
Messages
45
Hi

I am trying to execute the following query in my VBA code:

Code:
sQuery = "select * from tblVerticalTests where ((tblVerticalTests.chrReportID) = '" & Me.cboReportID & "') and ((tblVerticalTests.Airborne/Impact) = 'Airborne')"
You will see that tblVerticalTests has a field called "Airborne/Impact" - when I change this in the code to another field without a slash it works ok... So I am assuming that the "/" is the problem - does anyone know how i can refer to this field in a way that will not upset the code (I cant change the name of the field not as its used in other parts of the program and will take far too long to rectify!)

Thanks in advance for your help

Mike Wood
 
Howzit

Does this help...

Code:
sQuery = "select * from tblVerticalTests where ((tblVerticalTests.chrReportID) = " & Me.cboReportID & ") and (([tblVerticalTests]![Airborne/Impact]) = 'Airborne')"
 
Putting square brackets around it may help.

tblVerticalTests.[Airborne/Impact]

Also if chrReportID is a numeric data type you may need to loose the quotes:

((tblVerticalTests.chrReportID) = " & Me.cboReportID & ")

???

(Edit: Kiwi is too fast for the old man this morning - :p)
 
Simple(r) solution is to NOT use spaces or special characters ()_*&^%/?>< etc in table/column names to prevent this problem from occuring in the first place.
 

Users who are viewing this thread

Back
Top Bottom