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

MS Access Reports

P: n/a
Does anyone know how to run MS Access reports from I'd like to keep
the existing reports in the database if I can.

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
"David" <dm*******> wrote in message
Does anyone know how to run MS Access reports from I'd like to
keep the existing reports in the database if I can.

Here's a routine you can use: (watch for word-wrap)

You'll also need to add a reference to Access in your solution.
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("c:\Data\MyAccessFile. mdb")
'Create new query if needed
If sQryName.Length > 0 And sSQL.Length > 0 Then
oAccess.DoCmd.DeleteObject(Access.AcObjectType.acQ uery, sQryName)
'Close and reopen the Access object if above statement failed
oAccess.Visible = False
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oAccess)
oAccess.Visible = True
oAccess.OpenCurrentDatabase(gsCurLocation & gsCurDatabase)
End Try
oAccess.CurrentDb.CreateQueryDef(sQryName, sSQL)
End If
'Preview the report
oAccess.DoCmd.OpenReport(sReportName, Access.AcView.acViewPreview, , ,
'Close the Access Instance
If Not oAccess Is Nothing Then
' Call Access Quit method without saving any changes.
' 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 ge****
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.