i'm working at trying to get printing to work out properly myself. In order to print it out, it must be exported first into something such as a *.pdf file. I've got code that is working for that, but I'd like to have a print button where it would export into *.pdf, then call Adobe Acrobat and open the exported file there for printing.
Here's my code that is exporting the report into *.pdf:
' This subroutine exports a file into Adobe Acrobat in order to print it.
'Check to see if the application directory has a subdirectory called "C:\ExportFileName\".
'If not, create the directory since exported files will be placed here.
'This uses the Directory class of the System.IO namespace.
Dim ExportPath As String
ExportPath = "C:\ExportFileName\"
If Directory.Exists(ExportPath) = False Then
'Set the time for the file name in order to affix it the the created file.
Dim DateTimeNow As DateTime
Dim Yr As Int16
Dim Yr2 As String
Dim Mth As Int16
Dim mth2 As String
Dim Dy As Int16
Dim dy2 As String
Dim Hr As Int16
Dim hr2 As String
Dim Mn As Int16
Dim mn2 As String
Dim strDateTimeNow As String
DateTimeNow = Now()
Yr = Year(DateTimeNow)
Yr2 = Yr.ToString
Mth = Month(DateTimeNow)
If Mth <= 9 Then
mth2 = "0" + Mth.ToString
mth2 = Mth.ToString
Dy = Day(DateTimeNow)
If Dy <= 9 Then
dy2 = "0" + Dy.ToString
dy2 = Dy.ToString
Hr = Hour(DateTimeNow)
If Hr <= 9 Then
hr2 = "0" + Hr.ToString
hr2 = Hr.ToString
Mn = Minute(DateTimeNow)
If Mn <= 9 Then
mn2 = "0" + Mn.ToString
mn2 = Mn.ToString
strDateTimeNow = Yr2 + mth2 + dy2 + hr2 + mn2
' this allows me to login to my file. If no logon is needed, skip this step.
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
Dim crReportDocument As New ReportDocument
'ReportFullPathName is a variable I created that holds the path and name of the report file.
'Set the ConnectionInfo properties for logging on to the Database
'If you are using ODBC, this should be the DSN name NOT the physical server name. If
'you are NOT using ODBC, this should be the physical server name
.ServerName = "MRI_Dwh_Dev"
'If you are connecting to Oracle there is no DatabaseName. Use an empty string.
'For example, .DatabaseName = ""
.DatabaseName = ""
.UserID = strUID
.Password = strPWD
'This code works for both user tables and stored procedures. Set the CrTables to the Tables collection
'of the report
CrTables = crReportDocument.Database.Tables
'Loop through each table in the report and apply the LogonInfo information
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
crDiskFileDestinationOptions = New DiskFileDestinationOptions
crExportOptions = crReportDocument.ExportOptions
'Export to PDF
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + ReportName + strDateTimeNow + ".pdf"
'set the required report ExportOptions properties
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
'Once the export options have been set for the report, the report can be exported. The Export command
'does not take any arguments
' Export the report
'Response.WriteFile(ExportPath + ReportName + strDateTimeNow + ".pdf")
Catch err As Exception