Results 1 to 8 of 8
  1. #1
    Noob's Avatar
    Noob is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    36

    Debug.Print Stored SQL Querys

    Hi,

    I am trying to just write a little test to output the stored Query Names & the SQL strings within them.



    How I find it manually:

    Select the query, and then right click on it. Select "DesignView". From there click SQL & it reveals the statement.

    How would I do that in VBA?


    I have a Do loop where the queries are being executed. I can output the query name but not the SQL statement as a text string to the immediate window. I tried “.value” but it gives me an integer. I want to preview/ output the SQL string to the immediate window before it is executed.

    TIA

    Noob

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It would really help if you posted the VBA code...... I'm just sayin.,,,,,,

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    debug.print CurrentDb.QueryDefs("qMyQuery").SQL

  4. #4
    Noob's Avatar
    Noob is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    36
    It would really help if you posted the VBA code...... I'm just sayin.,,,,,,
    @ssanfu No doubt, but the company has data protection on lock down. I can't even send myself an e-mail among other things. lol...

  5. #5
    Noob's Avatar
    Noob is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    36
    @davergri thanks that looks about right. I am going to test it & will post back ASAP.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You will need a loop to show sql for all queries. Something along the lines of the following:
    eg
    For each qdf in Currentdb.querydefs
    debug.print qdf.name & vbtab & qdf.sql
    Next qdf

  7. #7
    Noob's Avatar
    Noob is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    36
    Cool thanks @orange.

    I am going to test that too. Thanks so... much

  8. #8
    Noob's Avatar
    Noob is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    36
    Haha......

    Yup!!!

    Code:
    Debug.Print CurrentDB.QueryDefs(rst!QRY_Name).SQL
    works great inside that Do Loop. Thanks again @davergri

    And the For Loop you shared @orange works great for a general purpose dump. WHOA!!! thanks alot.

    Best of all I understand whats going on there now.

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

Similar Threads

  1. Working with querys
    By CoreyM in forum Queries
    Replies: 18
    Last Post: 05-04-2012, 02:18 PM
  2. Report with two querys
    By karanvemuri in forum Reports
    Replies: 3
    Last Post: 10-03-2011, 09:36 AM
  3. Where are my Querys?
    By tamu46 in forum Access
    Replies: 7
    Last Post: 12-04-2010, 03:27 AM
  4. Print files stored in an OLE field
    By Brad Harris in forum Programming
    Replies: 1
    Last Post: 12-28-2009, 07:33 PM
  5. Understanding SQL Querys
    By jacobbiljo in forum Access
    Replies: 8
    Last Post: 11-17-2009, 05:17 PM

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