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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Access Report

Status
Not open for further replies.

stevedi

Programmer
Aug 23, 2002
23
US
Hi,

I've got a VB6.0 sub that I want to open access reports selected from a treeview. I'm using the Access 9.0 Object Library to reference the report object. It kinda works, it generates the report but the access app does not stay open. I briefly see the report then access closes. Any suggestions would be appreciated. thanks

Private Sub TreeView1_DblClick()

Dim objAccess As Object
Dim strDbName, strReportName As String

If Left(TreeView1.SelectedItem.Key, 1) = "X" Then

strDbName = "E:\temp\db1.mdb"
strReportName = "Report1"

Set objAccess = New Access.Application
objAccess.OpenCurrentDatabase ("E:\temp\db1.mdb")
With objAccess
' Make Access visible and Preview report on screen
.Visible = True
.DoCmd.OpenReport strReportName, acViewPreview, ""
.DoCmd.Maximize
' Show Print Preview Toolbar
.DoCmd.ShowToolbar "Database", acToolbarYes
.DoCmd.ShowToolbar "Print Preview", acToolbarYes
End With

End If
End Sub
 
Declare the MS Access object at module/form level, in the declarations section.

What is happening is that your code opens the Access object with a local object variable and continues to the end where the proceedure ends and the object variable goes out of scope and gets destroyed.

Make sure you destroy the object when it's not needed any longer.

Be advised that if you are distributing this application, all clients using it will need a licensed version of MS Access on their machines in order for this to work.

You might want to have a look at the MS SnapshotViewer, free from the MS Site, to show your reports, where the client doesn't need to have MS Access.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top