Calling the Report from VBA


As with forms, you can use the DoCmd to call your report within VBA. Let’s take a look at the code that follows.

Sub runReport()   Dim con As ADODB.Connection   Set con = New ADODB.Connection   con.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _   "Data Source=C:\BegVBA\thecornerbookstore.mdb;"   DoCmd.OpenReport "rptCustomer", acViewPreview End Sub 

We have one variation from the form here. If you enter the line with just

DoCmd.OpenReport "rptCustomer"

Access will assume you want to send the report directly to the printer. In order to prevent that from happening, for the time being, you need to add a second parameter of acViewPreview.

Of course, as in previous chapters, you could include the DoCmd within a decision structure to decide which report to run. In addition, you can include it as part of the Switchboard form created in Chapter 12.




Access VBA Programming
Microsoft Access VBA Programming for the Absolute Beginner
ISBN: 1598633937
EAN: 2147483647
Year: 2006
Pages: 214
Authors: Michael Vine

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net