access reports & queries

Ultrawhack

Well-known member
Joined
Jul 5, 2006
Messages
164
Location
Canada
Programming Experience
3-5
My entire app was designed in access2K fe/be complete with forms, queries and reports.

Now I would like to use VB.NET and design a frontend with the mdb as backend. I'm fairly new to vb.net

What is the best way to call access queries and reports from vb.net.

Thanks !
 
FYI

Access XP and newer, you can call the Office.Access class, run your query and generate the report through .NET 1.1 and above. Not sure about 1.0.

I think you will have problems calling a report from Access 2K using VB.net. In that scenario, you should use VBA or upgrade Access to XP or newer.

Here is some sample code for Access report and query calling. Remember, the query and report must be created before running this code...

Dim oAccess As Access.Application
oAccess =
New Access.ApplicationClass
oAccess.OpenCurrentDatabase(filepath:="c:\VB Examples\ATM V2\bin\BANK.mdb", Exclusive:=
True)

oAccess.Visible = True
oAccess.DoCmd.OpenReport(ReportName:="Mini_Stateme nt", View:=Access.AcView.acViewPreview, WhereCondition:="[account_no]= " & ca.account_no)

To print the actual report do this...

oAccess.Visible = False
oAccess.DoCmd.OpenReport(ReportName:="Mini_Stateme nt", View:=Access.AcView.acViewNormal, WhereCondition:="[account_no]=" & ca.account_no)
oAccess.DoCmd.Close()


I forgot the link to MSDN where I got this. There are different parameters you can put in, such as opening the report, or sending it directly to your default printer etc...
 
To get/retrieve data from the internal Access query you can simple refer it as you refer common MSAccess table. And for the reports as you will notice if you reread the code above you have to open database (means, nothing like display reports in your VB.NET application with only established connection). However, if you want to avoid this you can simply make the same reports in Crystal Reports which comes with VS.NET. All you need is to register the instance of the CR.

Regards ;)
 
Back
Top