开发者

Running and Printing a Access Report via VBScript and/or Command Line

开发者 https://www.devze.com 2023-04-11 10:09 出处:网络
I n开发者_如何转开发eed 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.Looking at How to use

I n开发者_如何转开发eed 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.


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

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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号