Solved

VB code to call Access report

Posted on 1998-07-23
3
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

751 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