Solved

VB code to call Access report

Posted on 1998-07-23
3
216 Views
Last Modified: 2013-11-28
I would like to call an access report from VB.
I’ve tried
db.myreport  = 1

That doesn’t work. What is the correct VB code to do this?

Thanks  
0
Comment
Question by:g6yassin
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 1466569
g6yassin,
Do you have access in your machine? I have the code for OLE automation. If you like, just click on my name and see the paq. It only cost 10 points. Then you can delete this one.
Regards
Dalin
0
 
LVL 9

Accepted Solution

by:
Dalin earned 30 total points
ID: 1466570
g6yassin,

Here is the code to open it with OLE automation: I realize that it may be quite a few paq to look for. If you already get it from the paq, reject my answer.
Regards
Dalin


       Have a command Named OpenAccessReport, in the click event, put the code:

           'handle errors
           On Error GoTo LoadError
             
           'change the mouse
           Screen.MousePointer = vbHourglass
             
           'create new object variable
           Dim objAccess As New access.Application
             
           'open database
           objAccess.OpenCurrentDatabase ("YourDBNameWithPath.MDB")
                 
           'maximize access
           objAccess.DoCmd.Maximize
             
           'run report in print preview mode
           objAccess.DoCmd.OpenReport "YourReportName", acViewPreview
           
           'restore report
           objAccess.DoCmd.Restore
             
           'maximize report
           objAccess.DoCmd.Maximize

           'change the mouse
           Screen.MousePointer = vbDefault
             
           'exit
           Exit Sub
             
       LoadError:
           'change the mouse
           Screen.MousePointer = vbDefault
             
           'show error
           MsgBox Error$
             
           Resume Next
0
 

Author Comment

by:g6yassin
ID: 1466571
Dalin
I am sorry for adding my comment a little late, but I am new to
the system and I am getting to know how the it works better
now. Your code worked well but the window starts minimized. I would like it start open.
Thanks
Yassin
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

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.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

831 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