Results 1 to 3 of 3
  1. #1
    reburton is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2013
    Posts
    14

    How do I Run SQL in VBA and pass the results to a variable?

    I am trying to figure out if this line of code is usable, but I don't know: DoCmd.RunSQL ("SELECT Max([BSRangeTbl].[Date]) AS MAXofDate FROM [BSRangeTbl];") I am stumped again, my usual state of mind.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    If you want the result in a variable, you'd have to open a recordset on that SQL. Alternatively you could use DMax().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In addition to what Paul said, the reason you cannot use that line of code is:

    The RunSQL command is used to execute a Microsoft Access action query.
    Action queries append, update or delete records. You cannot use RunSQL for a select query.

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

Similar Threads

  1. Replies: 15
    Last Post: 04-21-2011, 02:50 PM
  2. Pass variable name to another forms
    By Thomman in forum Access
    Replies: 3
    Last Post: 04-07-2011, 10:01 AM
  3. Pass Variable to Table Field with VBA
    By dgj32784 in forum Programming
    Replies: 3
    Last Post: 03-28-2011, 09:36 PM
  4. VBA Pass-through Query with Variable
    By smaumau in forum Programming
    Replies: 0
    Last Post: 12-06-2010, 09:10 AM
  5. Replies: 5
    Last Post: 04-05-2010, 11:43 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