Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

VB code to call Access report

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
g6yassin
Asked:
g6yassin
  • 2
1 Solution
 
DalinCommented:
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
 
DalinCommented:
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
 
g6yassinAuthor Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now