Re: Run an Access report in a VB .Net application

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.acQuery, sQryName)

Catch

'Close and reopen the Access object if above statement failed

oAccess.Visible = False

oAccess.Quit(Access.AcQuitOption.acQuitSaveNone)

System.Runtime.InteropServices.Marshal.ReleaseComObject(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.ReleaseComObject(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 george@xxxxxxxxxxxx
------------------------------------------------------------------------

"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



.



Relevant Pages

  • Re: Run an Access report in a VB .Net application
    ... How can I run the reports in Access from the VB application? ... Dim oAccess As New Access.ApplicationClass ... oAccess.OpenCurrentDatabase(gsCurLocation & gsCurDatabase) ... ' Use Marshal class' ReleaseComObject to release the Access instance. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MS Access Reports
    ... > Does anyone know how to run MS Access reports from VB.net. ... Public Sub PrintAccessReport(ByVal sReportName As String, ... Dim oAccess As New Access.ApplicationClass ... ' Use Marshal class' ReleaseComObject to release the Access instance. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MS Access Reports and VB.NET Program
    ... something else to keep in mind is, the future of your database. ... rewriting reports in the future. ... Dim oAccess As New Access.ApplicationClass ... ' Use Marshal class' ReleaseComObject to release the Access instance. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MS Access Reports and VB.NET Program
    ... the computer you want to run the report. ... Dim oAccess As New Access.ApplicationClass ... ' Use Marshal class' ReleaseComObject to release the Access instance. ... George Shubin Custom Software Development ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MS Access Reports and VB.NET Program
    ... 'Which of these 200 Crystal Reports point to database X' ... Dim oAccess As New Access.ApplicationClass ... ' Use Marshal class' ReleaseComObject to release the Access instance. ...
    (microsoft.public.dotnet.languages.vb)