EYoung
asked on
How auto export and how auto print - no viewing?
I have written many VB6 applications that use Crystal Reports to display reports on the screen and allow the users to do whatever they want with the reports, i.e. view, print, export, etc.
Now the users of the applications are asking for two new features. To automatically export the report to an Adobe Acrobat file or to automatically print the report to the default printer. In either case the user does not want to have the report shown on the screen. Just do the export or do the print, no viewing on the screen.
So I have created in VB6 some options that the users can click to select their choice, i.e. Send (export to Adobe, no viewing on screen), View (display report on screen) or Print (print to the printer, no viewing on screen.)
The Viewing code works just fine. However, I can't figure out how to "automatically" export to Adobe Acrobat or "automatically" print to the printer without first showing the CRViewer9 control on the screen.
Specifically I want to do the following:
Send - Not show the report in CRViewer, just export automatically to an Adobe Acrobat file in a predefined folder, i.e. "C:\Temp\" without any prompts.
View - Works just fine.
Print - Not show the report in CRViewer, just print automatically to the default printer without any prompts.
Below is the code I have been using in the VB6 form that shows the report:
************************** ********** ********** *********
Option Explicit
Dim Report As dsrSWR
Private Sub CRViewer92_PrintButtonClic ked(UseDef ault As Boolean)
UseDefault = False
Report.PrinterSetup (hWnd)
Report.PaperOrientation = crPortrait
'Report.PaperOrientation = crLandscape
On Error GoTo Cancel:
Report.PrintOut True
Cancel:
Exit Sub
End Sub
Private Sub Form_Activate()
Set Report = New dsrSWR
Report.EnableParameterProm pting = False
Report.ParameterFields(1). AddCurrent Value mSWR_Date
Report.ParameterFields(2). AddCurrent Value mEmployee_mKey
Report.ParameterFields(3). AddCurrent Value mFilled_or_Blank_Parm
Report.ParameterFields(4). AddCurrent Value mQuantity_Parm
Report.ParameterFields(5). AddCurrent Value mDefault_User_Name
Select Case mSend_View_or_Print_Parm
Case "S"
Unload Me
Case "V"
Screen.MousePointer = vbHourglass
CRViewer92.ReportSource = Report
CRViewer92.DisplayTabs = False
CRViewer92.DisplayToolbar = True
CRViewer92.EnableGroupTree = False
CRViewer92.EnableExportBut ton = True
CRViewer92.ViewReport
CRViewer92.Zoom (100)
Screen.MousePointer = vbDefault
Case "P"
Screen.MousePointer = vbHourglass
CRViewer92.ReportSource = Report
CRViewer92.DisplayTabs = False
CRViewer92.DisplayToolbar = True
CRViewer92.EnableGroupTree = False
CRViewer92.EnableExportBut ton = True
CRViewer92.ViewReport
CRViewer92_PrintButtonClic ked (True)
CRViewer92.Zoom (100)
Screen.MousePointer = vbDefault
End Select
End Sub
Private Sub Form_Resize()
CRViewer92.Top = 0
CRViewer92.Left = 0
CRViewer92.Height = ScaleHeight
CRViewer92.Width = ScaleWidth
End Sub
************************** ********** ********** *********
Thanks for the help.
Now the users of the applications are asking for two new features. To automatically export the report to an Adobe Acrobat file or to automatically print the report to the default printer. In either case the user does not want to have the report shown on the screen. Just do the export or do the print, no viewing on the screen.
So I have created in VB6 some options that the users can click to select their choice, i.e. Send (export to Adobe, no viewing on screen), View (display report on screen) or Print (print to the printer, no viewing on screen.)
The Viewing code works just fine. However, I can't figure out how to "automatically" export to Adobe Acrobat or "automatically" print to the printer without first showing the CRViewer9 control on the screen.
Specifically I want to do the following:
Send - Not show the report in CRViewer, just export automatically to an Adobe Acrobat file in a predefined folder, i.e. "C:\Temp\" without any prompts.
View - Works just fine.
Print - Not show the report in CRViewer, just print automatically to the default printer without any prompts.
Below is the code I have been using in the VB6 form that shows the report:
**************************
Option Explicit
Dim Report As dsrSWR
Private Sub CRViewer92_PrintButtonClic
UseDefault = False
Report.PrinterSetup (hWnd)
Report.PaperOrientation = crPortrait
'Report.PaperOrientation = crLandscape
On Error GoTo Cancel:
Report.PrintOut True
Cancel:
Exit Sub
End Sub
Private Sub Form_Activate()
Set Report = New dsrSWR
Report.EnableParameterProm
Report.ParameterFields(1).
Report.ParameterFields(2).
Report.ParameterFields(3).
Report.ParameterFields(4).
Report.ParameterFields(5).
Select Case mSend_View_or_Print_Parm
Case "S"
Unload Me
Case "V"
Screen.MousePointer = vbHourglass
CRViewer92.ReportSource = Report
CRViewer92.DisplayTabs = False
CRViewer92.DisplayToolbar = True
CRViewer92.EnableGroupTree
CRViewer92.EnableExportBut
CRViewer92.ViewReport
CRViewer92.Zoom (100)
Screen.MousePointer = vbDefault
Case "P"
Screen.MousePointer = vbHourglass
CRViewer92.ReportSource = Report
CRViewer92.DisplayTabs = False
CRViewer92.DisplayToolbar = True
CRViewer92.EnableGroupTree
CRViewer92.EnableExportBut
CRViewer92.ViewReport
CRViewer92_PrintButtonClic
CRViewer92.Zoom (100)
Screen.MousePointer = vbDefault
End Select
End Sub
Private Sub Form_Resize()
CRViewer92.Top = 0
CRViewer92.Left = 0
CRViewer92.Height = ScaleHeight
CRViewer92.Width = ScaleWidth
End Sub
**************************
Thanks for the help.
ASKER
Thanks mlmcc. I'll try it and get back to you. Glad to see I am not the only one working today. Good to hear from you...
ASKER
Instead of Word, how do I set the format type to Adobe Acrobat?
ASKER
mlmcc,
Here is the code for just printing. How do I not show the dialog box that asks for the print range and number of copies to print? (Everything with the print work fine.)
Private Sub srPrint_SWR()
'
' Open report and pass parameters
'
Set Report = New dsrSWR
Report.EnableParameterProm pting = False
Report.ParameterFields(1). AddCurrent Value mSWR_Date
Report.ParameterFields(2). AddCurrent Value mEmployee_mKey
Report.ParameterFields(3). AddCurrent Value mFilled_or_Blank_Parm
Report.ParameterFields(4). AddCurrent Value mQuantity_Parm
Report.ParameterFields(5). AddCurrent Value mDefault_User_Name
'
' Set flags for Report
'
Report.MorePrintEngineErro rMessages = False
Report.DisplayProgressDial og = False
'
' Print the report
'
Report.PrintOut
End Sub
Here is the code for just printing. How do I not show the dialog box that asks for the print range and number of copies to print? (Everything with the print work fine.)
Private Sub srPrint_SWR()
'
' Open report and pass parameters
'
Set Report = New dsrSWR
Report.EnableParameterProm
Report.ParameterFields(1).
Report.ParameterFields(2).
Report.ParameterFields(3).
Report.ParameterFields(4).
Report.ParameterFields(5).
'
' Set flags for Report
'
Report.MorePrintEngineErro
Report.DisplayProgressDial
'
' Print the report
'
Report.PrintOut
End Sub
ASKER
mlmcc,
I got the printing to work without prompting from a dialog box. The "False" option at the end did the trick. See below:
Private Sub srPrint_SWR()
'
' Open report and pass parameters
'
Set Report = New dsrSWR
Report.EnableParameterProm pting = False
Report.ParameterFields(1). AddCurrent Value mSWR_Date
Report.ParameterFields(2). AddCurrent Value mEmployee_mKey
Report.ParameterFields(3). AddCurrent Value mFilled_or_Blank_Parm
Report.ParameterFields(4). AddCurrent Value mQuantity_Parm
Report.ParameterFields(5). AddCurrent Value mDefault_User_Name
'
' Set flags for Report
'
Report.MorePrintEngineErro rMessages = False
Report.DisplayProgressDial og = False
'
' Print the report
'
Report.PrintOut False, mQuantity_Parm
End Sub
Now all I have to do is the exporting to Adobe Acrobat...
I got the printing to work without prompting from a dialog box. The "False" option at the end did the trick. See below:
Private Sub srPrint_SWR()
'
' Open report and pass parameters
'
Set Report = New dsrSWR
Report.EnableParameterProm
Report.ParameterFields(1).
Report.ParameterFields(2).
Report.ParameterFields(3).
Report.ParameterFields(4).
Report.ParameterFields(5).
'
' Set flags for Report
'
Report.MorePrintEngineErro
Report.DisplayProgressDial
'
' Print the report
'
Report.PrintOut False, mQuantity_Parm
End Sub
Now all I have to do is the exporting to Adobe Acrobat...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Am trying. Will get back to you...
ASKER
Can you supply the code for "MS_OUTLOOK_running"? Thanks
Maybe. I'll try to find it.
mlmcc
mlmcc
I apparently don't have it here. I'll check at work. It may have been a call to one of the dlls we included.
mlmcc
mlmcc
ASKER
I am getting a Run-time error when I try the export to Adobe. Message on screen is:
Run-time error '-214...
Error in File ??:
Missing or out-of-date export DLL.
Do you know which dll is needed? Thanks for the help.
Run-time error '-214...
Error in File ??:
Missing or out-of-date export DLL.
Do you know which dll is needed? Thanks for the help.
ASKER
Its the U2FCR.dll and I am working with the techs on it now. Will get back to you. See last posting in this link:
http://p2p.wrox.com/topic.asp?TOPIC_ID=7334
http://p2p.wrox.com/topic.asp?TOPIC_ID=7334
Glad you figured it out. We still use CR8 that doesn't have PDF as an export option.
mlmcc
mlmcc
ASKER
I really appreciate your help. You have provided much needed help over the years and I am grateful for all of it. I need to leave now but will be back first thing in the morning. (I am in California, US). Regards...
Here is some info on exporting to PDF using CR 8.5 - not sure if it applies well for CR 9. Anyway, I hope it might give you some ideas to get started. I automatically export to PDF with no problem using CR 9, but I'm using VS.Net (will send sample code if you'd like) - it's been years since I've used VB 6 and it's just not coming back to me (yikes - in the last 4 years went from VS 6 to .Net 2002, 2003, 2005 - CR 8.5, 9, 10, XI and each of the .Net versions in between - too much).
Please see: http://support.businessobjects.com/library/kbase/articles/c2010117.asp
Jan
ASKER
Thanks for the help to both of you. I am still getting an error message "Failed to export report" but I will do some research and possibly post another question.
mlmcc - if you find the routine to check on whether or not outlook is running, pleaes post.
Thanks again...
mlmcc - if you find the routine to check on whether or not outlook is running, pleaes post.
Thanks again...
Glad i could help
mlmcc
mlmcc
ASKER
dlls drive me crazy
Private crApp As CRAXDRT.Application
Private crRpt As CRAXDRT.Report
'
' Check if report is already in use
'
If IsObject(crRpt) Then
Set crRpt = Nothing
End If
'
' Open report
'
Set crApp = New CRAXDRT.Application
Set crRpt = crApp.OpenReport(txtReport
crRpt.RecordSelectionFormu
'
' Set flags for CRViewer
'
crRpt.MorePrintEngineError
crRpt.EnableParameterPromp
crRpt.DiscardSavedData
crRpt.DisplayProgressDialo
crRpt.PrintOut
Exporting to Word document and mailing it
Private crApp As CRAXDRT.Application
Private crRpt As CRAXDRT.Report
'
' Check if report is already in use
'
If IsObject(crRpt) Then
Set crRpt = Nothing
End If
'
' Open report
'
Set crApp = New CRAXDRT.Application
Set crRpt = crApp.OpenReport(txtReport
crRpt.RecordSelectionFormu
crRpt.MorePrintEngineError
crRpt.EnableParameterPromp
crRpt.DisplayProgressDialo
crRpt.DiscardSavedData
'
' Set export options
'
If MS_OUTLOOK_running Then
crRpt.ExportOptions.Destin
crRpt.ExportOptions.MailTo
crRpt.ExportOptions.MailSu
crRpt.ExportOptions.MailMe
crRpt.ExportOptions.Format
crRpt.Export False
mlmcc