Skip to content

Instantly share code, notes, and snippets.

@kbrammer
Last active August 29, 2015 13:56
Show Gist options
  • Save kbrammer/9235919 to your computer and use it in GitHub Desktop.
Save kbrammer/9235919 to your computer and use it in GitHub Desktop.
Export SQL Query Objects from Microsoft Access 2013
' http://msdn.microsoft.com/en-us/library/office/gg278834(v=office.15).aspx
Sub ExportQueryObjs()
' File System Properties
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
' DAO / Query definition properties
' http://stackoverflow.com/questions/20252599/how-do-you-export-ms-access-query-objects-to-text-file
Dim def As DAO.QueryDef
Dim defCol As DAO.QueryDefs
Set defCol = CurrentDb.QueryDefs
For Each def In defCol
Set f = fs.OpenTextFile("C:\" & def.Name & ".sql", ForWriting, TristateFalse)
f.Write def.SQL
f.Close
'Debug.Print def.Name & vbCrLf;
'Debug.Print def.SQL
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment