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/

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

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.

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
vern123Author Commented:
Edited text of question
vern123Author Commented:
Edited text of question
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
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
It does that. The Append file access method creates the file if it doesn't exist already.
vern123Author Commented:
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.