How to Run an Access Report

  • Thread starter Thread starter Kobeobo
  • Start date Start date
K

Kobeobo

Hi guys, sorry if this has been covered before...

I have a VB6 program using Access V2000 as the database. The Access DB
has several reports,
does anyone know how to execute (run) an Access report from within VB6?

Thanks
Baz
 
Kobeobo said:
I have a VB6 program using Access V2000 as the database. The Access DB
has several reports,
does anyone know how to execute (run) an Access report from within VB6?


Access is the only program that can run Access reports so
you'll have to use Automation to do from somewhere else.

I have never done that from VB so if you need help with it,
I suggest that you post another question to an Office
Automation newsgroup.
 
Baz,

As you are trying to do something *from VB*, this is really a question for
one of the 36 VB groups that all start with microsoft.public.vb.

(If you were trying to run a VB program *from Access*, this might have been
the right group to ask your question in.)

With that advice out of the way, you can't use any "Access" objects in an
mdb file outside of Access. Using an mdb file for data in VB is *NOT* using
Access. You are using the "Jet" data portion of the mdb file.

What you can do is use "automation" to control Access from VB and print out
reports. This does require that Access is installed on the computer you are
trying to do this.

Take a look at the article at
http://support.microsoft.com/default.aspx?scid=kb;EN-US;296586.

If you are trying to make a VB only solution, VB includes Crystal Reports
for making and distributing reports.

Good luck.

Sco
 
Just off the top of my head...

1. Add a reference to Access.
2. Add the following air code:
'Declarations Section
Private acc As Access.Application

Public Sub OpenAccessReport(sReportName As String)
Set acc = New Access.Application

acc.OpenCurrentDatabase "path to database", False
acc.DoCmd.OpenReport sReportName, acViewPreview
acc.DoCmd.Close acReport, sReportName
Stop
acc.CloseCurrentDatabase
Set acc = Nothing
End Sub

Since Access doesn't expose an automation library, you'll need some way of
detecting when the report closes/prints. I'd suggest:
Private WithEvents rpt As Access.Report
....and using a report event, such as Close(), to then trigger your code to
destroy the Access (and Report) objects.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
Sco, first off - sorry for posting in this newgroup - this was in error, i
thought i was in a vb group. Anyway, since you have responded and asked a
question (your 4th para), i guess i am trying to use automation as all i want
to be able to do is print the access report from vb6... and yes Access is
installed on the PC.
Baz
 
Well, if Access is installed and you want to use automation, article 296586
has everything you need.

Again, good luck.

Sco
 
Back
Top