Problem Opening Access Reports

  • Thread starter Thread starter ChrisP
  • Start date Start date
C

ChrisP

I am trying to open an Access report from my VB
application. It will not open the database. My VB program
continues t run with no errors, but it doesn't open
Access nor show the report. I could use some help. Below
is the code I used to do this.

Dim appAccess as New Access.Application

appAccess.OpenCurrentDatabase "C:\Biblio.mdb"
appAccess.DoCmd.OpenReport "ReportName", acViewPreview
appAccess.CloseCurrentDatabase
appAccess.Quit

Set appAccess = Nothing


Thanks ahead of time,
Chris
 
Believe it or not, your code *is* working.

You just can't see it.

Most apps are invisible when started with automation.

If you want to see Access and your print preview, you need to add:

appAccess.Visible = True

Just make sure that you watch *really, really, fast.*

Your code keeps running. The database is closed and Access is shut down
instantly after flashing the report preview so fast you probably won't even
see a flash on your screen. You can prove this by single stepping the code
after you add the Visible line.

If you were printing instead of previewing, you would have paper flying out
of your printer even thought you didn't see anything on the screen.

If you want to be able to actually *see* Access and the preview:

1 - Move the Dim app line from your routine to module level

2 - Change the Dim to Private (Not functionally necessary, but a good
programming practice.)

3 - Move the Close, Quit, and Set Nothing lines to another procedure

See below...

Good luck.

Sco

ChrisP said:
I am trying to open an Access report from my VB
application. It will not open the database. My VB program
continues t run with no errors, but it doesn't open
Access nor show the report. I could use some help. Below
is the code I used to do this.

Dim appAccess as New Access.Application

appAccess.OpenCurrentDatabase "C:\Biblio.mdb"
appAccess.DoCmd.OpenReport "ReportName", acViewPreview
appAccess.CloseCurrentDatabase
appAccess.Quit

Set appAccess = Nothing


Thanks ahead of time,
Chris

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Put this code in a form module with
'two command buttons called:
'cmdOpen
'cmdClose

Option Compare Database
Option Explicit

Private appAccess As New Access.Application

Sub cmdOpen_Click()

appAccess.OpenCurrentDatabase "C:\Biblio.mdb"
appAccess.DoCmd.OpenReport "ReportName", acViewPreview
appAccess.Visible = True

End Sub

Sub cmdClose_Click()

appAccess.CloseCurrentDatabase
appAccess.Quit

Set appAccess = Nothing

End Sub
 
Back
Top