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

Show a print preview of Access reports from VB.NET?

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.GetExecutin gAssembly.Location)

Return fi.Directory.ToString

End Function

Ken

------------------------------------

"Dean Slindee" <sl*****@charter.net> wrote in message
news:10*************@corp.supernews.com...
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

Nov 21 '05 #2

P: n/a
Thanks, Ken
That was exactly what I was looking for. Got it working against a .ade
application.
If the application's Visible property is set to False, then the report can
print without the Access GUI interface showing.
I don't suppose there is any way on a "print preview" mode to show only the
report preview window without the Access host window in the background?

Dean Slindee
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...
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.GetExecutin gAssembly.Location)

Return fi.Directory.ToString

End Function

Ken

------------------------------------

"Dean Slindee" <sl*****@charter.net> wrote in message
news:10*************@corp.supernews.com...
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.