将所有 MS Access SQL 查询导出到文本文件 [英] Export all MS Access SQL queries to text files
问题描述
我必须用许多宏查询等记录一个 MS Access 数据库.我希望使用代码将每个 SQL 查询提取到一个与查询名称相同的文件中,例如,如果查询名为 q_warehouse_issues,那么我希望将 SQL 提取到名为 q_warehouse_issues.sql 的文件中
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 if a query is named q_warehouse_issues then i wish to extract the SQL to a file named q_warehouse_issues.sql
我不想导出查询结果集,只想导出 SQL!
I DO NOT WISH TO EXPORT THE QUERY RESULT SET, JUST THE SQL!
我知道我可以在 Access 中手动执行此操作,但我厌倦了所有的点击、保存等操作.
I know I can do this manually in Access, but i am tired of all the clicking, doing saveas etc.
推荐答案
这应该会让你开始:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDB()
For Each qdf In db.QueryDefs
Debug.Print qdf.SQL
Next qdf
Set qdf = Nothing
Set db = Nothing
您可以使用文件系统对象或内置的 VBA 文件 I/O 功能将 SQL 写入文件.我假设您问的更多是关于如何获取 SQL,而不是关于如何写出文件,但是如果您需要,请在评论中说出来,我会编辑帖子(或者有人会发布他们自己的答案)说明).
You can use the File System Object or the built-in VBA File I/O features to write the SQL out to a file. I assume you were asking more about how to get the SQL than you were about how to write out the file, but if you need that, say so in a comment and I'll edit the post (or someone will post their own answer with instructions for that).
这篇关于将所有 MS Access SQL 查询导出到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!