Hi,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strDB As String = String.Format("{0}\Northwind.mdb", GetMyPath)
' Print report
OLEShowReport(strDB, "Invoice", Access.AcView.acViewNormal,
strWhere:="OrderId = 10251")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim strDB As String = String.Format("{0}\Northwind.mdb", GetMyPath)
'Print preview report
OLEShowReport(strDB, "Invoice", strWhere:="OrderId = 10251")
End Sub
Private Function OLEOpenReport(ByVal strDBName As String, _
ByVal strRptName As String, _
Optional ByVal intDisplay As Access.AcView = Access.AcView.acViewNormal, _
Optional ByVal strFilter As String = "", _
Optional ByVal strWhere As String = "") As Boolean
Dim bReturn As Boolean = True
Try
' Create Automation object.
Dim objAccess As New Access.Application
' Open the supplied database.
' Optional parameter at the end of statement
' indicates exclusive mode if set to True...
objAccess.OpenCurrentDatabase(strDBName, False)
' The OpenReport method uses the following arguments...
' Report Name - Name of the report object.
' View - Display in Print Preview or send to printer.
' acNormal - Print report
' acDesign - open report in design (n/a in runtime)
' acPreview - open in preview window
' Filter Name - Name of a saved filter query.
' Where Condition = valid SQL where condition.
objAccess.DoCmd.OpenReport(strRptName, intDisplay, strFilter, _
strWhere, Access.AcWindowMode.acWindowNormal)
' Close Microsoft Access session instance...
objAccess.Quit(Access.AcQuitOption.acQuitSaveNone)
objAccess = Nothing
Catch ex As Exception
bReturn = False
MessageBox.Show(ex.ToString, "Automation", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Try
Return bReturn
End Function
Private Function OLEShowReport(ByVal strDBName As String, _
ByVal strRptName As String, _
Optional ByVal intDisplay As Access.AcView = Access.AcView.acViewPreview, _
Optional ByVal strFilter As String = "", _
Optional ByVal strWhere As String = "") As Boolean
Dim bReturn As Boolean = True
Try
' Create Automation object.
Dim objAccess As New Access.Application
' Open the supplied database.
' Optional parameter at the end of statement
' indicates exclusive mode if set to True...
objAccess.OpenCurrentDatabase(strDBName, False)
' The OpenReport method uses the following arguments...
' Report Name - Name of the report object.
' View - Display in Print Preview or send to printer.
' acNormal - Print report
' acDesign - open report in design (n/a in runtime)
' acPreview - open in preview window
' Filter Name - Name of a saved filter query.
' Where Condition = valid SQL where condition.
objAccess.DoCmd.OpenReport(strRptName, intDisplay, strFilter, _
strWhere)
' Close Microsoft Access session instance...
'objAccess.Quit(Access.AcQuitOption.acQuitSaveNone)
objAccess = Nothing
Catch ex As Exception
bReturn = False
MessageBox.Show(ex.ToString, "Automation", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Try
Return bReturn
End Function
Private Function GetMyPath() As String
Dim fi As New
System.IO.FileInfo(Reflection.Assembly.GetExecutingAssembly.Location)
Return fi.Directory.ToString
End Function
Ken
------------------------------------
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 database?
Thanks,
Dean Slindee