Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VBA Access design (sql) view

VBA Access design (sql) view

Scheduled Pinned Locked Moved Visual Basic
databasedesignhelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FMpol
    wrote on last edited by
    #1

    I need help figuring out how to display the sql view of a query using VBA. I have an Access 2003 database that contains a little over 300 queries. Yikes! I know in Access you can open a query in Design view and then change the view to SQL view so that you can actually see the Select statement. Instead of doing that more than 300 times to cut and paste the query statement, I would like to write a quick macro to display the information. I was able to figure out how to loop through all my query objects and display the name, but I can't find a way to actually get at the sql view of the query. Below is the code I have: Dim obj As AccessObject Dim dbs As Object Set dbs = Application.CurrentData For Each obj In dbs.AllQueries MsgBox "sql view: " & obj.FullName Next obj When I watch the obj data, there isn't any properties for the sql view. I thought this information would be in there. Am I misunderstanding what this object contains? It seems like I'm pretty close because I'm able to see the name of all the queries I have in my DB. What crucial piece of information am I missing? Thanks, FMPol

    D 1 Reply Last reply
    0
    • F FMpol

      I need help figuring out how to display the sql view of a query using VBA. I have an Access 2003 database that contains a little over 300 queries. Yikes! I know in Access you can open a query in Design view and then change the view to SQL view so that you can actually see the Select statement. Instead of doing that more than 300 times to cut and paste the query statement, I would like to write a quick macro to display the information. I was able to figure out how to loop through all my query objects and display the name, but I can't find a way to actually get at the sql view of the query. Below is the code I have: Dim obj As AccessObject Dim dbs As Object Set dbs = Application.CurrentData For Each obj In dbs.AllQueries MsgBox "sql view: " & obj.FullName Next obj When I watch the obj data, there isn't any properties for the sql view. I thought this information would be in there. Am I misunderstanding what this object contains? It seems like I'm pretty close because I'm able to see the name of all the queries I have in my DB. What crucial piece of information am I missing? Thanks, FMPol

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You may want to try looking at this[^]. If that doesn't work for you, I got more results from a carefully worded Google search, "vba access query sql text[^]". No, seriously, I had to go through about 15 search phrases to find the right combination of keywords.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You may want to try looking at this[^]. If that doesn't work for you, I got more results from a carefully worded Google search, "vba access query sql text[^]". No, seriously, I had to go through about 15 search phrases to find the right combination of keywords.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        F Offline
        F Offline
        FMpol
        wrote on last edited by
        #3

        Thanks Dave that was exactly what I needed. I think every google search I tried had 'view' in it and that must have been my big problem. I've posted the new code below: Dim db As Database Set db = CurrentDb Dim curSQL As String Dim qrynam As String For Each qrydef In db.QueryDefs qrynam = qrydef.Name curSQL = qrydef.SQL MsgBox "sql name: " & qrynam & Chr$(13) & "sql view: " & curSQL Next

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups