Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Access reports from VB6

Status
Not open for further replies.

Ham

Technical User
Feb 23, 2000
122
US
I have an application that is a mix of VB6 and Access2000 using DAO. All the data entry and manipulation is done via the VB6 front end. I set up the original tables directly in Access, and do all the reporting in Access. I would like to isolate the users completely from Access (I'm about to retire from this organization). I can create a front end in VB6 to set up the tables initially, but don't know how I could print the reports. I can, via VB6, set up the queries underlying the reports, but is there a way to actually print the reports? I have avoided VBA because this application does tons of list manipulation and uses the ListBox.AddItem (not supported in VBA) zillions of times. Any suggestions? Thanks. -- Ham Rutledge
 
Simple enough.

Instantiate an Access object in VB and use the Docmd object from the Access object.

So

Dim app As New Access.Application
app.DBEngine.OpenDatabase ("YourDBPath")

app.DoCmd.OpenReport "Name of report"

app.CloseCurrentDatabase

Set app = Nothing

will do what you're after.

Craig
 
Craig - thanks for the reply. I'm still having a problem. I set up a test program and included Microsoft Access 9.0 Object Library in the references. When I run it, it hangs on the DoCmd statement with the error message 2486: "You can't carry out this action at the present time." Is there another reference that I should have? The other ones included are:"Visual Basic for Applications"; "Visual Basic runtime objects and procedures"; "Visual Basic objects and procedures"; "OLE Automation" and "Microsoft DAO 3.6 Object Library". Assuming we get past whatever I'm doing wrong here. I have another question. My program accessses the database via the Set DBS= statement. Can I just use the DoCmd statement? Thanks -- Ham
 
Not enough to give you an answer. But by the look of it, you're instantiating a database (by the Set DBS = ) line. You need to instantiate an application, not a database.

But your code would help.

Craig
 
Hi,

One way I've done this from VB6 is using the SnapShot Viewer (Free download from Microsoft).

The following VB6 code creates a snapshot of the Access report, and then opens it in the snapshot viewer. You can then print it.

Downside is that you need Snapshot Viewer on all machines.

Code:
Dim appAccess As New Access.Application

appAccess.OpenCurrentDatabase "C:\Databasename.mdb", True
appAccess.DoCmd.OpenReport "ReportName", acViewPreview
appAccess.DoCmd.OutputTo acOutputReport, "ReportName", "Snapshot Format", "c:\temp.snp", True
appAccess.Quit
Set appAccess = Nothing

There are two ways to write error-free programs; only the third one works.
 
<code>

Dim app As New Access.Application

With app
.Visible = True
.DoCmd.Maximize
.OpenCurrentDatabase "C:\WINNT\Profiles\CLORNE\My Documents\db1.mdb", False
.DoCmd.OpenReport "Report1", acPreview, , strSQL
End With

Set app = Nothing

</code>
 
Craig - this does work in my test program. Now I'll try to incorporate this into the real thing. I may be back with more questions. Many many thanks. -- Ham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top