How to save messages from VBA code to a text file?

J

Jojo

I am new to VBA coding. I would like to save messages to a log file so
I can monitor my Macro's process by the messages in the log file. Can
anyone give me a sample code to save messages to a file?

Thanks.

-Jojo
 
D

Douglas J. Steele

Well, macros in Access aren't VBA coding, but I'll assuming you really do
want VBA.

I typically create a sub like the following:

Sub DebugPrint(OutputMessage As String)
Dim intFile As Integer
Dim strFile As String

strFile = CurrentProject.Path & "/Output.txt"
intFile = FreeFile
Open strFile For Append As #intFile
Write #intFile, OutputMessage
Close #intFile

End Sub

I then use this like:

DebugPrint "The routine is calculating the variance"

or

Call DebugPrint("The routine is calculating the variance")
 
G

Guest

Douglas J. Steele said:
Well, macros in Access aren't VBA coding, but I'll assuming you really do
want VBA.

I typically create a sub like the following:

Sub DebugPrint(OutputMessage As String)
Dim intFile As Integer
Dim strFile As String

strFile = CurrentProject.Path & "/Output.txt"
intFile = FreeFile
Open strFile For Append As #intFile
Write #intFile, OutputMessage
Close #intFile

End Sub

I then use this like:

DebugPrint "The routine is calculating the variance"

or

Call DebugPrint("The routine is calculating the variance")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top