Solved

VB6 - Run an Access Report from VB6

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…

828 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