Results 1 to 3 of 3

Thread: Global Variable in Query

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    3

    Post

    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!

  2. #2
    Guest

    Post

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    3

    Post

    Thank you very much! That was exactly it!
    I really appreciate it!
    HAVE A GREAT DAY!

    ------------------
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width