Extra! Macro Scripting - Writing to Log Issue

I have a macro script that inputs data into SAP via Extra screens.

I want to be able to write out errors to a log file.  I have it set up as follows:

Dim chan570Errors As Long                                  'output channel
'Open the channel
File_OpenWrite chan570Errors, strFileLoc & "\Logs\" & Format(Now(), "ddmmyyyy-hhmmss") & "ErrorLog.csv"
'Print out Headers
Print #chan570Errors, "Date", "Error", "POW Record Number", "Item No.", "File Name", "File Location", "Full Location"
'Function Call
    Write_Errors ("Missing Vendor")


'Functions
Sub Write_Errors(strErrText As String)
  'Print out error to channel
  Print #chan570Errors, Now, strErrText, strPOWRecNo, strItemNo, strFileName, strFileLoc,  
  strFullImportFileName
   
  MyScreen.WaitHostQuiet 1000  
End Sub

Sub File_OpenWrite(myChannel As Long, pathName As String)
    myChannel = FreeFile                                   'Return the next unused file number
    Open pathName For Output As #myChannel                 'Open the channel
End Sub
-----------------------------------------------------------------------------------------
The problem that I am having is that I have the Write_Errors function call in several different areas of the script.  However, it will only write to the log file the Header and the first error that it encounters.  It doesn't write out an subsequent errors (there are more since I am testing for all possibilities).

Any ideas as to why this is happening?

Thanks in advance.

Capn

   
CapnCrnchAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SCDMETACommented:
Are you getting any runtime errors?  If so, they would be helpful.

Could you turn on error handling in the Write_Errors function?  The Print statement might be throwing an error that is getting ignored by the macro interpreter.

Sub Write_Errors(strErrText As String)
  On Error Goto Errortrap
  'Print out error to channel
  Print #chan570Errors, Now, strErrText, strPOWRecNo, strItemNo, strFileName, strFileLoc,  strFullImportFileName    
  MyScreen.WaitHostQuiet 1000  
  Exit Sub
Errortrap:
    msgbox "Error:" & err.description
End Sub

Is "Dim chan570Errors As Long" falling out of scope, between calls to your macros?  

Try opening the file, writing to the file and closing it all within Write_Errors function.  Not very efficient but it could get you past the problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CapnCrnchAuthor Commented:
SCDMETA wrote:
Try opening the file, writing to the file and closing it all within Write_Errors function.  Not very efficient but it could get you past the problem.

---------------------
This is what I ended up doing.  Not very efficient, but it works nonetheless.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.