Mark Epstein
asked on
Office automation - open a report in MS aAccess with VB6
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.OpenCurrentDatab ase 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.
Here is my code:
Dim appAccess As New Access.Application
Dim OrderID as Integer
appAccess.OpenCurrentDatab
appAccess.Visible = True
appAccess.DoCmd.OpenReport
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is essentially the same as the other solutions. My problem was that I was not using proper syntz for the where clause. Thank you all!
ASKER
the second link was much better. The solution was easier than I thought. I thought that I would have to access the table in my database as an object, and then set a criteria for the OrderID field within the table, but the problem was as simple as "OrderID = 12345" as the WhereCondition string. I actually found this post a week ago, but somehow missed the solution.
Thank you very much fo helping me solve my first question on EE!