PDA

Click to See Complete Forum and Search --> : Global Variable in Query


NewQuest
Jul 28th, 1999, 06:30 PM
I am using VB 6.0 with and Access database.
I am trying to use a global variable in the where clause of my query. I have include my code and you can assume that all variables, etc. are declared and used correctly. I know this for sure, because if I take the where clause out of my query it returns the first record in the PatientInfo table.

I believe my syntax is off or I am just missing some quotes or something??

Note: I have received two different run-time errors with two different values for the global variable *CellValue*
A)The first error is: No value given for one or more required parameters CellValue = NAME
B)The second error is: Syntax error (missing operator) in query expression "[Patient Name]
=A Third" CellValue=A Third (This is just a test value)

strQuery = "select * from PatientInfo"
strQuery = strQuery & " where [Patient Name]="
strQuery = strQuery & CellValue
adoPrimaryRS.Open strQuery, db,adOpenStatic, adLockOptimistic

Any help would be greatly appreciated!!! :)
Thank you and if I have repeated a similiar question, please refer me to the answer.


------------------
Thanks! :)

Jul 28th, 1999, 07:39 PM
Just a guess, but if your variable is a string variable you'll need single quotes around 'A Third'.

strQuery = strQuery & "'" & CellValue & "'"

Without the single quotes, the query will think it's some kind of object which has not been defined.

NewQuest
Jul 28th, 1999, 09:54 PM
Thank you very much! That was exactly it!
I really appreciate it!
HAVE A GREAT DAY! :)

------------------
Thanks! :)