ms-access - 如何将 ACCESS DB 中的 sql 查询结果写入 txt 文件?
问题描述
MS Office 365 专业增强版,访问 2007 - 2016
我需要能够捕获 Access DB 的查询结果并将其发送到 C 驱动器上的 txt 文件。这将使用任务调度程序(我在想)将运行某种脚本以 1x/wk 完成。我发现了不同的基于 SQL Server 的示例,但对于 Access 却没有。
谁能提供一个如何做到这一点的例子?
解决方案
1.从任务调度程序中,您实际上可以调用可以触发模块的宏。研究这个,因为我不知道我头顶的语法,但它真的很容易(只需在它之后使用 ax/callmymacro 命令执行应用程序)
创建文本文件非常简单。您可以像上面提到的那样使用 DoCmd.TransferText 导出,您可以在代码中构建它,特别是如果查询结果没有所有内容或者您只需要某些部分。这是一个快速而肮脏的模板。
'this is only a template for proof of concept for you - google syntax of how to appropriately
'declare and use recordsets. Same with declaring other variables
'if your text file requieres headers, google how to loop through recordset headers.
'Pretty easy stuff
sep = "|" 'your choice of delimiter
NewTextFile = "pathwhereyouwanttodropyourfile.FileNametxt"
Open NewTextFile For Output As #2
do until rs.eof
'wholeLine is a string variable used to store the currentline of the text file.
WholeLine = WholeLine & rs("filed1") & sep
Print #2, WholeLine
WholeLine = "" 'important to reset variable
rs.movenext
Loop
Close #2
*如果你弄清楚如何使用数组而不是循环遍历记录集,你会得到很酷的分数。*
推荐阅读
- css - 不希望 Textarea 过渡适用于调整大小
- r - 使用 dplyr 按行计算百分位数时出错
- r - dyn.load 中的“RCurl”加载失败:无法加载共享对象 - Rstudio - openSuse
- php - .htaccess (?) 子文件夹后缺少斜杠的问题
- xquery - 是否有可能每次使用 xdmp:random() 或 Marklogic 中的其他方式生成一个 6 位唯一随机数
- tally - Tally 使用哪种算法来验证输入的 GST 编号是否正确?
- c - 通过网络发送不同大小数据的最佳实践
- javascript - 无法使用 Sequelize 在数据库 SQLite-Database 中找到匹配项
- html - 固定位置干扰现场滚动
- kotlin - 如何在 Kotlin 中使用 Associate