Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008

    Unanswered: Using variable in recordset?

     recordset = Database.OpenRecordset("SELECT A, B FROM Table WHERE A = Variable") 
    Is it possible to use a variable in recordset?

  2. #2
    Join Date
    May 2003
    Provided Answers: 5
    yes depending on the variable type you would use the following synatx

    for a string
    dim mystr as string
    mystr = "Test"
    ("SELECT A, B FROM Table WHERE A = " & "'" & mystr & "'")
    the quotes are on the left and right of my test are actually a double , single, and then double " ' " - like this but no spaces

    for a number
    dim mynum as integer or you could just say
    dim mynum (which is the same as dim mynum as variant)
    mynum = me!txtnumfield (if you are referncing a field on the current form)
    ("SELECT A, B FROM Table WHERE A = " & mynum)

    for a date you need to parse in the # symbol
    dim mydate
    mydate = Date
    ("SELECT A, B FROM Table WHERE A = #" & mydate & "#")
    Dale Houston, TX

  3. #3
    Join Date
    Aug 2008
    Awesome. 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