Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Adelaide, South Australia, Australia
    Posts
    146
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Does anyone know of a VBA command that will enable me to capture the SQL behind a query? I'd like to loop through all the queries (can already do that) and store the SQL in a text or memo field in another table, but have been unable to find the right command. (I thought I might be able to open the query in SQL view and somehow take a snapshot of that, but can only find the ordinary Design view.)

    Thanks

    Alison

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Here is a partial block of code

    If you know how to loop through all the queries, set strquery to the name of each query.
    Then for each query, set qdf to be that. The you can access its sql property.

    Code:
    Dim sql As String
    Dim strquery As String
    Dim qdf As DAO.QueryDef
    Set qdf = CurrentDb.QueryDefs(strquery)
    sql = qdf.sql
    Regards
    John



  3. #3
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Adelaide, South Australia, Australia
    Posts
    146
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Many thanks, John - just what I was looking for.

    Cheers

    Alison

Posting Permissions

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