Office automation - open a report in MS aAccess with VB6
Posted on 2007-08-03
I am using a vb6 front end form tied to a back end MSAccess 11 database. I want to programatically open the database, and open a report. The report will print an inovice, so it will need to be one specific record from the Orders table in the database. The OrderID is supplied at runtime from the vb6 form, and is used as the filter to open the report to the one specific record that I wish to see on the report.
Here is my code:
Dim appAccess As New Access.Application
Dim OrderID as Integer
appAccess.OpenCurrentDatabase C:\MyDB.mdb, True, "password"
appAccess.Visible = True
appAccess.DoCmd.OpenReport "rptInvoice", acViewPreview
rptInvoice is the report in Access. In the last line, after "acViewPreview", the next two parameters are "filter" and "WhereCondition". I need to know what to put in for the "WereCondition" that will convey to the Access database theOrderID on the VB6 form that is to match the "OrderID" in the Orders table of the database.
After I create a new instance of Access, I should have the ability to see all the objects and properties of the database. What I think I need to do is to find out how to reference the field 'OrderID' in the ' tblOrders'
of the database and put the value found in the txtOrderID text box on the vb6 form into the Where Condition of the DoCmd OpenReport statement.