使用VBA导出所有的MS Access SQL查询到文本文件 [英] Using VBA to export all MS Access SQL queries to text files

查看:236
本文介绍了使用VBA导出所有的MS Access SQL查询到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多的宏查询文件MS Access数据库,等等。我想用code,提取每个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).

这篇关于使用VBA导出所有的MS Access SQL查询到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆