Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1

    Unanswered: Set variable to query result.

    Help! My Access must be a bit rusty, here.
    I'm trying to set a variable to the return value of a query statement, and I can't remember the syntax. Here is what I have:

    Set ReturnValue = DoCmd.RunSQL("SELECT TOP 1 CheckTypes.CheckTypeID FROM CheckTypes ORDER BY CheckTypes.CheckType;")

    ...but the DoCmd won't compile, so this is obviously incorrect. I'm sure the answer is simple, but I appreciate any help you can give me.

    Thanks
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by blindman
    Help! My Access must be a bit rusty, here.
    I'm trying to set a variable to the return value of a query statement, and I can't remember the syntax. Here is what I have:

    Set ReturnValue = DoCmd.RunSQL("SELECT TOP 1 CheckTypes.CheckTypeID FROM CheckTypes ORDER BY CheckTypes.CheckType;")

    ...but the DoCmd won't compile, so this is obviously incorrect. I'm sure the answer is simple, but I appreciate any help you can give me.

    Thanks
    Yes. RunSQL requires an ACTION query ...

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    So what is the correct method of assigning a query result to a variable?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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