Results 1 to 4 of 4
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Gettting Query Definition

    Can you return the query used by a recordsource?



    Like Set rs= Currentdb.OpenRecordsource ("Select * from Table1;")

    Then later, the equivalent of
    Debug,print rs.sql (which doesn't exist)

    and get Select * from Table1

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Put the sql string into a variable and refer to that in both instances?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Your title suggests you know the answer already
    strSql = CurrentDb.QueryDefs("myQuery").sql
    so
    Set rs = currentdb.openrecordset(strSql)

    Why would you want that when you have the stored query?

    EDIT - or are you saying you want to know what stored query has that sql? I say no, not really. Any number of queries could contain that exact sql.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Hmm okay.. well in my (often) convoluted way I was raising an error - and the error handler needed something to resume to.
    The current recordsets sql seems as good as any.... but I couldn't get it to try...
    I used something else in the end, but thanks for the solution as it's worth remembering.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-30-2016, 05:36 AM
  2. Changing Field definition within a query
    By gm_lowery in forum Queries
    Replies: 5
    Last Post: 08-30-2012, 09:19 AM
  3. Replies: 2
    Last Post: 03-27-2012, 01:59 AM
  4. Definition Tables using a Query?
    By AccessMaccess in forum Access
    Replies: 5
    Last Post: 03-22-2011, 10:01 AM
  5. Criteria Definition
    By claing in forum Access
    Replies: 1
    Last Post: 12-19-2005, 07:46 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