Else
‘Print report
appAccess.DoCmd.OpenReport “rptCustomerLabels”
End If
Set appAccess = Nothing
If the MSE is already open, you can open a new script for editing by dragging the script
file from an Explorer pane into the MSE window.
Northwind.accdb has a form for selecting an invoice to print by order number. But you might want
to be able to quickly print an invoice without opening the database; the PrintInvoice.vbs script
listed next does just this:
Dim appAccess
Dim strDBName
Dim lngInvoiceNo
Dim strTitle
Dim strPrompt
Set appAccess = _
WScript.CreateObject(“Access.Application”)
Set fso = _
WScript.CreateObject(“Scripting.FileSystemObject”)
strDBName = “D:\Documents\Northwind.accdb”
On Error Resume Next
appAccess.OpenCurrentDatabase strDBName
Set fil = fso.GetFile(strDBName)
If fil Is Nothing Then
strPrompt = “Can’t find “ & strDBName & _
“; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
Quit
Else
strTitle = “Select invoice”
strPrompt = “Select an invoice to print (10248 - 11077)”
lngInvoiceNo = CLng(InputBox(strPrompt, strTitle))
‘MsgBox “Invoice No.: “ & lngInvoiceNo
Run a lengthy SQL statement to create a table for use as a report record source:
strSQL = “SELECT DISTINCT qryInvoices.OrderID, “ _
& “qryInvoices.ShipName, qryInvoices.ShipAddress, “ _
& “qryInvoices.ShipCityStateZip, “ _
TIPTIP
Part III Adding More Functionality to Office