Export all MS Access SQL queries to text files

后端 未结 5 1518
失恋的感觉
失恋的感觉 2020-12-08 07:32

I have to document an MS Access database with many many macros queries, etc. I wish to use code to extract each SQL query to a file which is named the same as the query, eg

5条回答
  •  独厮守ぢ
    2020-12-08 08:12

    1. In the VB Window, click Tools->References....
    2. In the References window add the dependency Microsoft Scripting Runtime by checking it off.

    Then this code will export the queries to a file suitable for using grep on:

    Sub ExportQueries()
    
      Dim fso As New FileSystemObject
    
      Dim stream As TextStream
    
      Set stream = fso.CreateTextFile("e:\temp\queries.txt")
    
      Dim db As DAO.Database
      Dim qdf As DAO.QueryDef
    
      Set db = CurrentDb()
      For Each qdf In db.QueryDefs
    
        stream.writeline "Name: " & qdf.Name
        stream.writeline qdf.SQL
        stream.writeline "--------------------------"
      Next qdf
      Set qdf = Nothing
      Set db = Nothing
    
    End Sub
    

提交回复
热议问题