Solved

VB6 - Run an Access Report from VB6

Posted on 2008-10-24
2
139 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now