A family of Microsoft relational database management systems designed for ease of use.
Nice work, integrating PowerShell with your Python script.
Continued success with the project.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Team
I am currently working on a project to retrieve queries definition from MS Access DB using python and even after trying different ways I am unable to extract queries. Any help on this will be highly appreciated.
Ways I tried.
Thankyou!
Dinesh
A family of Microsoft relational database management systems designed for ease of use.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Nice work, integrating PowerShell with your Python script.
Continued success with the project.
Thanks both of you for your suggestions :) :)
I think I found a way to fetch queries definition. I constructed one powershell script to extract only queries definition and integrated it with my python code and its working as expected.. It sounds unusual but working for me..
######################################################################
param([Parameter(Mandatory = $true)][string]$database_path,[Parameter(Mandatory = $true)][string]$output_directory)#$database_path = "C:\Users\rc08750\Downloads\Merit TX SUT Detail Refund Review 0605-1005.accdb"#$output_directory = "C:\Users\rc08750\Downloads\queries"
try {# Open the database$access.OpenCurrentDatabase($database_path)# Get the Queries collection$db = $access.CurrentDb()$queries = $db.QueryDefs
finally {#Closing current DB$db.close()# Ensure the database is closed even if an error occurs$access.CloseCurrentDatabase()# Quit Access application$access.Quit()# Release COM object[System.Runtime.Interopservices.Marshal]::ReleaseComObject($access) | Out-Null
#Closing all MSAccess processesStop-Process -Name MSACCESS}
I would go with George's suggestion to export to a table. That would make it easier to import into your new systems.
But there is a non code alternative. If you use the Database Documenter built into Access, you can write all the queries including their SQL statements to Word Doc
I suspect that the more complicated Access queries are going to be less similar to the Databricks views than you might anticipate, but that remains to be seen. Particularly if some of the queries are parameterized, or if they use Access specific expressions. One would hope, of course, that those differences are minimal.
You could adapt the procedure you show to write out the SQL into text files that you could then use to create the views.
Or, you might use it to write the SQL into Long Text fields in a table in the accdb, and then extract that table, with those SQL strings, for your use. You already know how to retrieve tables.
In either case, you could write a loop that goes through a recordset of the querydefs in an accdb, one at a time, and add that SQL to a new record in the table.