By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,900 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,900 IT Pros & Developers. It's quick & easy.

Run an Access report in a VB .Net application

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.