473,473 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Run an Access report in a VB .Net application

I'm in the process of migrating a MS Access 2003 application to VB .Net
(2005). How can I run the reports in Access from the VB application?
--
Tony
Aug 11 '06 #1
3 6455
Tony,

Probably with Office integration, be aware that the end users needs all full
licence of MS office access for that.

Cor

"Tony A." <To***@discussions.microsoft.comschreef in bericht
news:0E**********************************@microsof t.com...
I'm in the process of migrating a MS Access 2003 application to VB .Net
(2005). How can I run the reports in Access from the VB application?
--
Tony

Aug 12 '06 #2
I'm in the process of migrating a MS Access 2003 application to VB .Net
(2005). How can I run the reports in Access from the VB application?
Try the following. It requires Microsoft's Access to be installed on the
user's system. (Watch out for wordwrap.)

Public Sub PrintAccessReport(ByVal sReportName As String, Optional ByVal
sQryName As String = "", Optional ByVal sSQL As String = "")

Dim oAccess As New Access.ApplicationClass

oAccess.Visible = True

oAccess.OpenCurrentDatabase(gsCurLocation & gsCurDatabase)

oAccess.DoCmd.Minimize()

'Create new query if needed

If sQryName.Length 0 And sSQL.Length 0 Then

Try

'oAccess.CurrentDb.QueryDefs.Delete(sQryName)

oAccess.DoCmd.DeleteObject(Access.AcObjectType.acQ uery, sQryName)

Catch

'Close and reopen the Access object if above statement failed

oAccess.Visible = False

oAccess.Quit(Access.AcQuitOption.acQuitSaveNone)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oAccess)

oAccess.Visible = True

oAccess.OpenCurrentDatabase(gsCurLocation & gsCurDatabase)

oAccess.DoCmd.Minimize()

End Try

oAccess.CurrentDb.CreateQueryDef(sQryName, sSQL)

End If

'Preview the report

oAccess.DoCmd.OpenReport(sReportName, Access.AcView.acViewPreview, , ,
Access.AcWindowMode.acDialog)

'Close the Access Instance

If Not oAccess Is Nothing Then

' Call Access Quit method without saving any changes.

oAccess.Quit(Access.AcQuitOption.acQuitSaveNone)

' Use Marshal class' ReleaseComObject to release the Access instance.

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oAccess)

' Dereference the oAccess variable.

oAccess = Nothing

End If

End Sub

------------------------------------------------------------------------
George Shubin Custom Software Development
dX Software Systems Database Applications
Ph: 503-981-6806 Fax: 503-982-0120
www.dxonline.com ge****@dxonline.com
------------------------------------------------------------------------

"Despite efforts by government to prevent concentration in industry, the
regulators are bringing us to the point where only the largest companies can
survive." -- Henry Ford
Aug 12 '06 #3
Just interested in knowing where there might be more info/articles/tutorials
on 'Access Automation' using VBE (i.e., other aspects of this - not just
reports)??

--
Thanks!
Soddy
"George Shubin" wrote:
I'm in the process of migrating a MS Access 2003 application to VB .Net
(2005). How can I run the reports in Access from the VB application?

Try the following. It requires Microsoft's Access to be installed on the
user's system. (Watch out for wordwrap.)

Public Sub PrintAccessReport(ByVal sReportName As String, Optional ByVal
sQryName As String = "", Optional ByVal sSQL As String = "")

Dim oAccess As New Access.ApplicationClass

oAccess.Visible = True

oAccess.OpenCurrentDatabase(gsCurLocation & gsCurDatabase)

oAccess.DoCmd.Minimize()

'Create new query if needed

If sQryName.Length 0 And sSQL.Length 0 Then

Try

'oAccess.CurrentDb.QueryDefs.Delete(sQryName)

oAccess.DoCmd.DeleteObject(Access.AcObjectType.acQ uery, sQryName)

Catch

'Close and reopen the Access object if above statement failed

oAccess.Visible = False

oAccess.Quit(Access.AcQuitOption.acQuitSaveNone)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oAccess)

oAccess.Visible = True

oAccess.OpenCurrentDatabase(gsCurLocation & gsCurDatabase)

oAccess.DoCmd.Minimize()

End Try

oAccess.CurrentDb.CreateQueryDef(sQryName, sSQL)

End If

'Preview the report

oAccess.DoCmd.OpenReport(sReportName, Access.AcView.acViewPreview, , ,
Access.AcWindowMode.acDialog)

'Close the Access Instance

If Not oAccess Is Nothing Then

' Call Access Quit method without saving any changes.

oAccess.Quit(Access.AcQuitOption.acQuitSaveNone)

' Use Marshal class' ReleaseComObject to release the Access instance.

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oAccess)

' Dereference the oAccess variable.

oAccess = Nothing

End If

End Sub

------------------------------------------------------------------------
George Shubin Custom Software Development
dX Software Systems Database Applications
Ph: 503-981-6806 Fax: 503-982-0120
www.dxonline.com ge****@dxonline.com
------------------------------------------------------------------------

"Despite efforts by government to prevent concentration in industry, the
regulators are bringing us to the point where only the largest companies can
survive." -- Henry Ford
Dec 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how...
2
by: Matt Sogla | last post by:
I was wondering if it is possible to take a canned report ( on an Access database (Access XP version), and then be able to write a C# application that will make a call to the canned report in...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
3
by: Newbie | last post by:
This is my first try at running Access Report by Visual Basic I have the following code in my button press event: ' 2 - Show print preview objAccess.DoCmd.OpenReport "Invoices", 2, , ".=" & _...
8
by: jbonifacejr | last post by:
This is my first day here, so please be patient. I do not know how to search very well so the search I tried to get the answer showed me topics from the year 2000 and they really don't cover what I...
16
by: JoeW | last post by:
I'm utilizing a database that I created within MS Access within a program I've created in VB.NET. I am using the VB front end to navigate the information, but want to be able to print a report,...
0
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.