Solved

VB6 - Run an Access Report from VB6

Posted on 2008-10-24
2
141 Views
Last Modified: 2010-04-30
I have a report (ClosingRpt) that was created in Access 2002.  I wish to run that report from my VB6 program by pressing a Command Button (RunClosingRpt).

Do I use OLE?  If so, how.  If not, what do I do?

When the report has been run I want control to return to the VB6 program named "Evaluation"

thanks
0
Comment
Question by:ljcor
2 Comments
 
LVL 2

Accepted Solution

by:
Adel87 earned 500 total points
ID: 22802153
The attached code is supposed to do the trick :

before adding this code to your command button please do the following :
1- in VB6 go to 'Project' menu and choose ''References'
2- check the following refrence or the relevent version that you have :
'Microsft Access 10.0 Object Library'
3- press ok

don't forget to change the strPath the path you have your file in as this code asumes the Access mdb file to be on the same folder as the executable. and change db.mdb with the correct file name for your database file.

put the first part of the code (before the comment) in the command button and the second part in the (form_unload) event.

Please contact me if you need further assistance.

Best Regards,
Dim AcApp As Access.Application
Set AcApp = New Access.Application
Dim strPath As String
 
strPath = App.Path
strPath = strPath & "\db.mdb"
 
AcApp.OpenCurrentDatabase strPath
AcApp.Visible = True
AcApp.DoCmd.OpenReport "ClosingRpt", acViewPreview
AcApp.DoCmd.Maximize
 
'don't forget to dispose of the object when you close the form you are calling from, _
'otherwise repeated calls will end up with loads of instances of MSAccess running on your PC
 
AcApp.Quit
Set AcApp = Nothing

Open in new window

0
 

Author Closing Comment

by:ljcor
ID: 31509861
I thank you very much for this code.
Jack
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question