err Log in a txt file

I need A function so that if I call the function and it records/post the string to the last entry of the textfile specified in the pathname.

Private Function(PathName as string,ErrText as string)

 
if the function were called 4 times, A further example

Private Function("c:/err/err.txt","err1")
Private Function("c:/err/err.txt","err2")
Private Function("c:/dd/other.txt","otherfile")
Private Function("c:/err/err.txt","err3")

the resulting file err.txt would look like in c:/err/
err1
err2
err3

the resulting file other.txt would look like in c:/dd/
otherfile

if file exists in dir it would append the text
if file is not found in dir then a new one must be created.
The file should be closed and saved after.

I need the complete working code for this Function

Thank you.




vern123Asked:
Who is Participating?
 
MikeP090797Connect With a Mentor Commented:
Function Log(szFile as string, szMessage as string)
  Dim n as long
  n = freefile
  Open szFile for Append as #n
  Print #N, szMessage
  Close #N
End Function
0
 
vern123Author Commented:
Edited text of question
0
 
vern123Author Commented:
Edited text of question
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
vern123Author Commented:
Edited text of question
0
 
vern123Author Commented:
Thanks mike, but I also need the function to add the file
(If it does not already exist) with the correct name/path
0
 
MikeP090797Commented:
It does that. The Append file access method creates the file if it doesn't exist already.
0
 
vern123Author Commented:
:)
0
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.

All Courses

From novice to tech pro — start learning today.