通过VBScript和/或命令行运行和打印访问报告 [英] Running and Printing a Access Report via VBScript and/or Command Line
问题描述
我需要通过vbscript或命令行运行并打印Access报告.我看过很多地方,但我仍然迷路.我出于自动化目的需要这样做.
I need to run and print a Access report via vbscript or a command line. I have looked in many places but I remain lost. I need to do this for automation purposes.
推荐答案
查看如何使用命令行在Microsoft Access中切换,我看不到从命令行打开特定报告的选项.但是,您可以通过创建一个宏来打印报告并在命令行上的/x开关后加上宏名称来间接地做到这一点.
Looking at How to use command-line switches in Microsoft Access, I don't see an option to open a specific report from the command line. However, you could do it indirectly by creating a macro to print your report and including the macro name following the /x switch on the command line.
"Path to MSACCESS.EXE" "Path to your db file" /x YourMacroName
我对宏的处理不多.如果不适合使用宏来打印报告,则可以创建一个VBA函数来执行此操作,然后设计宏以简单地运行您的函数.
I don't do much with macros. If creating a macro to print the report isn't suitable, you could create a VBA function to do it, and design the macro to simply run your function.
如果您喜欢VBScript,请尝试此操作.除了更改常量的值之外,它可能还需要进行其他工作.
If you prefer VBScript, try this. It might need work beyond changing the values of the constants.
Option Explicit
Dim appAccess
Const cstrFolder = "C:\Access\webforums\"
Const cstrMdb = "whiteboard2003.mdb"
Const cstrReport = "rptFoo"
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase cstrFolder & cstrMdb, False
appAccess.DoCmd.OpenReport cstrReport, 0 ' acViewNormal = 0
appAccess.DoCmd.Close 3, cstrReport ' acReport = 3
appAccess.Quit
Set appAccess = Nothing
这篇关于通过VBScript和/或命令行运行和打印访问报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!