473,841 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
2 14140
Hi,

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim strDB As String = String.Format(" {0}\Northwind.m db", GetMyPath)

' Print report

OLEShowReport(s trDB, "Invoice", Access.AcView.a cViewNormal,
strWhere:="Orde rId = 10251")

End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click

Dim strDB As String = String.Format(" {0}\Northwind.m db", GetMyPath)

'Print preview report

OLEShowReport(s trDB, "Invoice", strWhere:="Orde rId = 10251")

End Sub

Private Function OLEOpenReport(B yVal strDBName As String, _

ByVal strRptName As String, _

Optional ByVal intDisplay As Access.AcView = Access.AcView.a cViewNormal, _

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.Applicat ion

' Open the supplied database.

' Optional parameter at the end of statement

' indicates exclusive mode if set to True...

objAccess.OpenC urrentDatabase( 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(str RptName, intDisplay, strFilter, _

strWhere, Access.AcWindow Mode.acWindowNo rmal)

' Close Microsoft Access session instance...

objAccess.Quit( Access.AcQuitOp tion.acQuitSave None)

objAccess = Nothing

Catch ex As Exception

bReturn = False

MessageBox.Show (ex.ToString, "Automation ", MessageBoxButto ns.OK,
MessageBoxIcon. Information)

End Try

Return bReturn

End Function

Private Function OLEShowReport(B yVal strDBName As String, _

ByVal strRptName As String, _

Optional ByVal intDisplay As Access.AcView = Access.AcView.a cViewPreview, _

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.Applicat ion

' Open the supplied database.

' Optional parameter at the end of statement

' indicates exclusive mode if set to True...

objAccess.OpenC urrentDatabase( 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(str RptName, intDisplay, strFilter, _

strWhere)

' Close Microsoft Access session instance...

'objAccess.Quit (Access.AcQuitO ption.acQuitSav eNone)

objAccess = Nothing

Catch ex As Exception

bReturn = False

MessageBox.Show (ex.ToString, "Automation ", MessageBoxButto ns.OK,
MessageBoxIcon. Information)

End Try

Return bReturn

End Function

Private Function GetMyPath() As String

Dim fi As New
System.IO.FileI nfo(Reflection. Assembly.GetExe cutingAssembly. Location)

Return fi.Directory.To String

End Function

Ken

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

"Dean Slindee" <sl*****@charte r.net> wrote in message
news:10******** *****@corp.supe rnews.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
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***@bellsout h.net> wrote in message
news:uV******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim strDB As String = String.Format(" {0}\Northwind.m db", GetMyPath)

' Print report

OLEShowReport(s trDB, "Invoice", Access.AcView.a cViewNormal,
strWhere:="Orde rId = 10251")

End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click

Dim strDB As String = String.Format(" {0}\Northwind.m db", GetMyPath)

'Print preview report

OLEShowReport(s trDB, "Invoice", strWhere:="Orde rId = 10251")

End Sub

Private Function OLEOpenReport(B yVal strDBName As String, _

ByVal strRptName As String, _

Optional ByVal intDisplay As Access.AcView = Access.AcView.a cViewNormal, _

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.Applicat ion

' Open the supplied database.

' Optional parameter at the end of statement

' indicates exclusive mode if set to True...

objAccess.OpenC urrentDatabase( 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(str RptName, intDisplay, strFilter, _

strWhere, Access.AcWindow Mode.acWindowNo rmal)

' Close Microsoft Access session instance...

objAccess.Quit( Access.AcQuitOp tion.acQuitSave None)

objAccess = Nothing

Catch ex As Exception

bReturn = False

MessageBox.Show (ex.ToString, "Automation ", MessageBoxButto ns.OK,
MessageBoxIcon. Information)

End Try

Return bReturn

End Function

Private Function OLEShowReport(B yVal strDBName As String, _

ByVal strRptName As String, _

Optional ByVal intDisplay As Access.AcView = Access.AcView.a cViewPreview, _
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.Applicat ion

' Open the supplied database.

' Optional parameter at the end of statement

' indicates exclusive mode if set to True...

objAccess.OpenC urrentDatabase( 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(str RptName, intDisplay, strFilter, _

strWhere)

' Close Microsoft Access session instance...

'objAccess.Quit (Access.AcQuitO ption.acQuitSav eNone)

objAccess = Nothing

Catch ex As Exception

bReturn = False

MessageBox.Show (ex.ToString, "Automation ", MessageBoxButto ns.OK,
MessageBoxIcon. Information)

End Try

Return bReturn

End Function

Private Function GetMyPath() As String

Dim fi As New
System.IO.FileI nfo(Reflection. Assembly.GetExe cutingAssembly. Location)

Return fi.Directory.To String

End Function

Ken

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

"Dean Slindee" <sl*****@charte r.net> wrote in message
news:10******** *****@corp.supe rnews.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2953
by: Joris Kempen | last post by:
Hi people, I know that the question has come around sometimes: How to open an Access Report using ASP and export it to for example RTF. I'm trying to implement the first method of David Cline: http://www.15seconds.com/issue/981216.htm
3
3542
by: Bob Darlington | last post by:
When I press F1 in print preview, I get the following error message for some (but not all) reports: 'The expression on Key Down you entered as the event property setting, produced the following error: There was an error loading an ActiveX control on one of your forms or reports.' After clicking OK on the error dialog, the correct custom help screen opens as expected.
0
1193
by: Robert | last post by:
I find that most of the time my Access reports are displayed in print preview mode rather than printed on the printer. Converting these reports to a form with a continuous view is difficult because of the lack of sorting and grouping on forms. Is there no other way to make a display-friendly report in Access? How do you currently create reports that are for viewing online instead of printing? Robert
1
2136
by: WJA | last post by:
A user of one of my databases is having the following problem. When they open any report in print preview that is formatted for landscape, it will display in portrait view when first opened. If they close the report and reopen it, it will display in the correct landscape view as will any other landscape formatted reports that are subsequently opened. The first opening and closing seems to "fix" the problem. All reports use the default...
1
5725
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me to use the above controls, example 1. The bottom two subroutines will print a graphic file, example...
1
3772
by: hgm_kh | last post by:
My MS-Access application was working perfectly under WIN95/98. When I converted the MS-Access application to run on WIN-XP, some reports which have $-value colums, do no longer print as shown in print preview. Actually, the columns do print, but all values are just blank. When I used a friend's PC (WIN-XP), that same report printed just fine. I wonder if there is a parameter within my WIN-XP that is the cause of my problem. Any suggestions would...
16
6544
by: JoeW | last post by:
I'm utilizing a database that I created within MS Access within a program I've created in VB.NET. I am using the VB front end to navigate the information, but want to be able to print a report, that I've also created within MS Access. I've attempted using the Access.Application instance, but I get errors when it tries to load the database. Just wondering if anyone has any experience with this, and what I should do. Thanks for any...
1
3096
by: mailjaneen | last post by:
Hello, can someone help me. I want to display some fields on a report in print preview (i.e. instructions), that I don't want to print to the printer or export to file. I can't seem to find any way of telling that the report is displaying in print preview, vs. being actually printed or emailed/ exported. So for example when previewing, I'd do Me!.Visible = True.
1
4299
by: Scorp Scorp | last post by:
Dear All, I designed a report, and bound with some data, the retreived data is 7 coloumns. I set a buttong to open the report in print preview, also to show display the page in landscape. Now on report design view it shows the width of the report to be 22". When the report is displayed, the 6th colomn and the 7th colomn are showed on a new page, moreover the 6th colomn is showed splitted, half of text on one page and the other on the...
0
9864
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9703
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10609
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10302
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7024
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.