Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2007
    Posts
    1

    Need help - Record set based on a program variable

    Hi
    I am quite new to VBA and access 2003 and I know this should be very easy.

    I am trying to open a record set where the critieria is based on a program variable.
    For example


    <statements to provide connection to table>


    Dim productionrun as string


    productionrun = "1234"

    rst.Open "select * from specimendata where runnumber = productionrun ", conn, adOpenForwardOnly, adLockReadOnly


    I am hopeing this would select all records from the table specimendata where the field runnumber is equal to that of the variable productionrun (in this case 1234).

    If I substitute productionrun for '1234' it works fine, I just can't seem to pass the variable across.

    Any ideas on how best to do this.
    Thanks

  2. #2
    jya is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2007
    Location
    Chicagoland
    Posts
    109
    You need to move the end quote before your variable.

    rst.Open "select * from specimendata where runnumber = " & productionrun, conn, adOpenForwardOnly, adLockReadOnly

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Ticketing program for community theater
    By Bill in forum Database Design
    Replies: 8
    Last Post: 11-22-2012, 02:15 PM
  2. Passing a value from a variable to an update query
    By MUKUDU99 in forum Programming
    Replies: 0
    Last Post: 08-24-2008, 11:14 PM
  3. Variable question
    By synapse5150 in forum Programming
    Replies: 1
    Last Post: 07-09-2008, 08:17 AM
  4. Deleting Record Contents, not complete record...
    By Charles Waters in forum Access
    Replies: 2
    Last Post: 06-24-2008, 12:00 PM
  5. pass a variable to the MsgBox function
    By 3dmgirl in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 07:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums