Solved

Open Access Reports in vb.net

Posted on 2006-06-30
4
758 Views
Last Modified: 2013-11-28
Hello!

I tried to make my dotnet win form show an Access Report. I have tried the following code,

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

            Dim acc_App As Access.Application = New Access.Application 'use this early binding if only have one version of access
           'Dim acc_App As Access.Application = CreateObject("Access.Application")
            acc_App.OpenCurrentDatabase("C:\myAccess.mdb", True)
            'above line will make msaccess.exe running as seen under taskmanager
            acc_App.DoCmd.OpenReport("test", Access.AcView.acViewPreview)
            acc_App.DoCmd.OpenReport("rptCustOrderAck", Access.AcView.acViewPreview)
            acc_App.Quit()

        End Sub

The first OpenReport did not bring anything to screen, and second one caused error meesage in the Access, ( as it should if I run previw after I launched the mdb).

What is missing here? Thanks!
0
Comment
Question by:ommer
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 17021659
Did you actually see the Access app open? Often you have to set .Visible=True (after opening).

0
 
LVL 3

Expert Comment

by:IainTheVBALearner
ID: 17026097
Hello

I got this to work.  

I didn't reference the Access object library, I just used an object.

I think the bit you're missing is making Access visible - as LSM said.

        Dim acc_App As Object

        acc_App = CreateObject("Access.Application")

        acc_App.OpenCurrentDatabase("C:\Projects.mdb", True)
        acc_App.visible = True
        acc_App.DoCmd.OpenReport("Report1", 2)
        acc_App.DoCmd.OpenReport("Report2", 2)

Iain

0
 

Author Comment

by:ommer
ID: 17026918
I will try that when I get to work. One reason that I choose the library is that I want to set the where condition and OpenArgs and pass them to the reports.
0
 
LVL 3

Expert Comment

by:IainTheVBALearner
ID: 17027263
...and you get intellisense.  I was just being lazy!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 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