I have included the macro code that I am having a problem running. The macro creates a comma delimited CSV file that is used as the input for an Impromptu report that passes in 2 prompt values. The CSV file is read until the end of the file is reached and a separate PDF file is created for every code that is read in. However, when I step through the macro in debug mode it completes successfully by creating a PDF files for each input record, but when the macro is executed in run mode the following error message is generated: "Visual C++ runtime error program: c:\progra~1\Cognos\cer1\bin\ImpAdmin.exe abnormal program termination."
Thanks in advance for any help that is provided.
MACRO CODE:
Sub Main()
' ***** Declare Objects *****
Dim ImpAppObj as Object
Dim ImpRepObj as Object
Dim objPDFPub as Object
' ***** Declare variables *****
Dim RowCnt as Integer
Dim EmailName as String
Dim EmailCo as String
Dim EmailTrdSqN as String
Dim cad_string as String
Dim cad_code as String
Dim seq_num as String
Dim ConfirmPrompt as String
' ***** Assigns Variables *****
ImpAppStr = "CognosImpromptu.Application"
AtomCat = "C:\ATOM\Impromptu\Catalogs\ATOMTEST.CAT"
UserClassId = "User"
UserClassPW = " "
DatabaseID = "SOMEID"
DatabasePW = "SOMEPW"
ConfirmRpt = "C:\ATOM\PromptEMReport_gdcp.imr "
ConfirmCdsRpt = "C:\ATOM\CfmTrdCds.imr"
RptOutputDir = "C:\ATOM\"
EmailOutputDir = "C:\ATOM"
ErrorLogFile = "C:\ATOM\Error.log"
RowCnt = 1
On Error Goto LogError
set ImpAppObj = CreateObject(ImpAppStr)
ImpAppObj.OpenCatalog AtomCat, UserClassId, UserClassPW, DatabaseID, DatabasePW
' ***** CREATES THE COMMA DELIMITED FILE FOR INPUT *****
set ImpRepObj = ImpAppObj.OpenReport(ConfirmCdsRpt)
ImpRepObj.RetrieveAll
ImpRepObj.ExportASCII RptOutputDir & "CfmTrdCds.csv"
ImpRepObj.CloseReport
set ImpRepObj = Nothing
' ***** OPEN OUTPUT FILE FOR READING IN CONFIRM ADDRESS CODES *****
Open "C:\ATOM\CfmTrdCds.csv" For Input Access Read As #1
Line Input #1, cad_string
Do While Not EOF(1)
Line Input #1, cad_string
cad_code = GetField(cad_string, 1, ","
seq_num = GetField(cad_string, 2, ","
ConfirmPrompt = cad_code & "|" & seq_num
set ImpRepObj = ImpAppObj.OpenReport(ConfirmRpt, ConfirmPrompt)
set ImpRepObj = ImpAppObj.ActiveDocument
ImpRepObj.RetrieveAll
set objPDFPub = ImpRepObj.PublishPDF
EmailName = ImpRepObj.GetDataValue(17,RowCnt)
EmailCo = ImpRepObj.GetDataValue(18,RowCnt)
EmailTrdSqN = ImpRepObj.GetDataValue(19,RowCnt)
objPDFPub.Publish EmailOutputDir & Rtrim(EmailName) & EmailCo & "_" & EmailTrdSqN & ".pdf"
ImpRepObj.CloseReport
set ImpRepObj = Nothing
Loop
Close #1
ImpAppObj.CloseCatalog
ImpAppObj.Quit
Goto EndMacro
LogError:
filenumber = FreeFile
Open ErrorLogFile For Output As filenumber
ErrStr = "EMAILCONFIRM.mac error: " & Err & " occured at line: " & Erl
Print #filenumber, ErrStr
Close #filenumber
Exit Sub
EndMacro:
End Sub
Thanks in advance for any help that is provided.
MACRO CODE:
Sub Main()
' ***** Declare Objects *****
Dim ImpAppObj as Object
Dim ImpRepObj as Object
Dim objPDFPub as Object
' ***** Declare variables *****
Dim RowCnt as Integer
Dim EmailName as String
Dim EmailCo as String
Dim EmailTrdSqN as String
Dim cad_string as String
Dim cad_code as String
Dim seq_num as String
Dim ConfirmPrompt as String
' ***** Assigns Variables *****
ImpAppStr = "CognosImpromptu.Application"
AtomCat = "C:\ATOM\Impromptu\Catalogs\ATOMTEST.CAT"
UserClassId = "User"
UserClassPW = " "
DatabaseID = "SOMEID"
DatabasePW = "SOMEPW"
ConfirmRpt = "C:\ATOM\PromptEMReport_gdcp.imr "
ConfirmCdsRpt = "C:\ATOM\CfmTrdCds.imr"
RptOutputDir = "C:\ATOM\"
EmailOutputDir = "C:\ATOM"
ErrorLogFile = "C:\ATOM\Error.log"
RowCnt = 1
On Error Goto LogError
set ImpAppObj = CreateObject(ImpAppStr)
ImpAppObj.OpenCatalog AtomCat, UserClassId, UserClassPW, DatabaseID, DatabasePW
' ***** CREATES THE COMMA DELIMITED FILE FOR INPUT *****
set ImpRepObj = ImpAppObj.OpenReport(ConfirmCdsRpt)
ImpRepObj.RetrieveAll
ImpRepObj.ExportASCII RptOutputDir & "CfmTrdCds.csv"
ImpRepObj.CloseReport
set ImpRepObj = Nothing
' ***** OPEN OUTPUT FILE FOR READING IN CONFIRM ADDRESS CODES *****
Open "C:\ATOM\CfmTrdCds.csv" For Input Access Read As #1
Line Input #1, cad_string
Do While Not EOF(1)
Line Input #1, cad_string
cad_code = GetField(cad_string, 1, ","
seq_num = GetField(cad_string, 2, ","
ConfirmPrompt = cad_code & "|" & seq_num
set ImpRepObj = ImpAppObj.OpenReport(ConfirmRpt, ConfirmPrompt)
set ImpRepObj = ImpAppObj.ActiveDocument
ImpRepObj.RetrieveAll
set objPDFPub = ImpRepObj.PublishPDF
EmailName = ImpRepObj.GetDataValue(17,RowCnt)
EmailCo = ImpRepObj.GetDataValue(18,RowCnt)
EmailTrdSqN = ImpRepObj.GetDataValue(19,RowCnt)
objPDFPub.Publish EmailOutputDir & Rtrim(EmailName) & EmailCo & "_" & EmailTrdSqN & ".pdf"
ImpRepObj.CloseReport
set ImpRepObj = Nothing
Loop
Close #1
ImpAppObj.CloseCatalog
ImpAppObj.Quit
Goto EndMacro
LogError:
filenumber = FreeFile
Open ErrorLogFile For Output As filenumber
ErrStr = "EMAILCONFIRM.mac error: " & Err & " occured at line: " & Erl
Print #filenumber, ErrStr
Close #filenumber
Exit Sub
EndMacro:
End Sub