I need to email a report to department heads with only their information. I have a report that I pass the date in from a VB6 application, a list of dept numbers and email addresses are read from a file. The first time through the report works fine, the email goes out. However, the second time through I get: "Run-time error '-2147190908 (80047784)': Failed to export the report" The dept # and email addresses are correctly being extracted from the file.
The error is occuring on the line "Rep.export(false)". I have stripped out some of the extra code and error checking to reduce confussion.
Any help would be greatly appreciated.
Private Sub cmdProcess_Click()
Set Rep = crxApplication.OpenReport(DENReportPath & "RPT335D.RPT", 1)
Rep.ReportTitle = Me.Caption
Rep.ReportComments = Rep.ReportComments & "Date Range: " _
& txtStartDate.text & " - " & txtEndDate.text
'build selection formula based on date range
D1 = SQLdate(txtStartDate.text) '*** Convert date to SQL format
D2 = SQLdate(txtEndDate.text)
SF = "{CCO_MST_DATE.MST_DATE} IN DATE(" & D1 & " TO DATE(" & D2 & ""
Comments = " All Departments All Items"
Rep.Database.LogOnServer "P2SODBC.DLL", "ATICTS" '*** Log into database
If Err Then
If Err <> "-2147192184" Then 'Cancel login
msg = "Unable to establish connection, error = " & Err & " - " & Err.Description
Call MsgBox(msg, StyleEx, ATICTS)
End If
Err.Clear
Hourglass False
Exit Sub
End If
Set RSFFile = d3Conn.brOpenFile("RSF" '*** Open Rpt Setup File -- List of Depts and emails
SF = Rep.RecordSelectionFormula '*** Set base formula, changes on dept
For X = 1 To RSFRec.brExtract(2).brDCount(VM) '*** Loop through departments
Dpt = RSFRec.brExtractStr(2, X) '*** Dept Number
Rep.RecordSelectionFormula = SF & " and {CCO.MST_DEPT_ALL} = '" _
& Dpt & "'" '*** Add dept as part of selection
Rep.ExportOptions.DestinationType = crEDTEMailMAPI
Rep.ExportOptions.FormatType = crEFTExactRichText
Rep.ExportOptions.MailSubject = "Consumable Usage Report By Date Range"
Rep.ExportOptions.MailMessage = "For Department: " & Dpt
ToString = RSFRec.brExtractStr(3, X) '*** Dept Head to email
CCString = RSFRec.brExtractStr(4, X) '*** Send CC to this person
MainEmail = ""
CCMail = ""
MainEmail = ToString
CCMail = CCString
Rep.ExportOptions.MailToList = "" '*** Clear out previous recipients
Rep.ExportOptions.MailToList = MainEmail
Rep.ExportOptions.MailCcList = CCMail
If Rep.ExportOptions.MailToList <> "" Then '*** Only export if email address
Rep.Export (False) '**** This is where the error is occuring ****
End If
Next X
The error is occuring on the line "Rep.export(false)". I have stripped out some of the extra code and error checking to reduce confussion.
Any help would be greatly appreciated.
Private Sub cmdProcess_Click()
Set Rep = crxApplication.OpenReport(DENReportPath & "RPT335D.RPT", 1)
Rep.ReportTitle = Me.Caption
Rep.ReportComments = Rep.ReportComments & "Date Range: " _
& txtStartDate.text & " - " & txtEndDate.text
'build selection formula based on date range
D1 = SQLdate(txtStartDate.text) '*** Convert date to SQL format
D2 = SQLdate(txtEndDate.text)
SF = "{CCO_MST_DATE.MST_DATE} IN DATE(" & D1 & " TO DATE(" & D2 & ""
Comments = " All Departments All Items"
Rep.Database.LogOnServer "P2SODBC.DLL", "ATICTS" '*** Log into database
If Err Then
If Err <> "-2147192184" Then 'Cancel login
msg = "Unable to establish connection, error = " & Err & " - " & Err.Description
Call MsgBox(msg, StyleEx, ATICTS)
End If
Err.Clear
Hourglass False
Exit Sub
End If
Set RSFFile = d3Conn.brOpenFile("RSF" '*** Open Rpt Setup File -- List of Depts and emails
SF = Rep.RecordSelectionFormula '*** Set base formula, changes on dept
For X = 1 To RSFRec.brExtract(2).brDCount(VM) '*** Loop through departments
Dpt = RSFRec.brExtractStr(2, X) '*** Dept Number
Rep.RecordSelectionFormula = SF & " and {CCO.MST_DEPT_ALL} = '" _
& Dpt & "'" '*** Add dept as part of selection
Rep.ExportOptions.DestinationType = crEDTEMailMAPI
Rep.ExportOptions.FormatType = crEFTExactRichText
Rep.ExportOptions.MailSubject = "Consumable Usage Report By Date Range"
Rep.ExportOptions.MailMessage = "For Department: " & Dpt
ToString = RSFRec.brExtractStr(3, X) '*** Dept Head to email
CCString = RSFRec.brExtractStr(4, X) '*** Send CC to this person
MainEmail = ""
CCMail = ""
MainEmail = ToString
CCMail = CCString
Rep.ExportOptions.MailToList = "" '*** Clear out previous recipients
Rep.ExportOptions.MailToList = MainEmail
Rep.ExportOptions.MailCcList = CCMail
If Rep.ExportOptions.MailToList <> "" Then '*** Only export if email address
Rep.Export (False) '**** This is where the error is occuring ****
End If
Next X