Create text file vbs

Our Accounts package has some basic vb scripting functionality.

I have created a function that works when a purchase receipt is posted, it emails users if a parameter is true.

I only want to send one message per order so I thought I would create a text file in C:\Temp.
e.g 'Ordernumber.txt'. On subsequent receipts I can check if the file exists to prevent duplicate emails being sent.

Can anyone help with the syntax?
HKFueyAsked:
Who is Participating?
 
Alex_WConnect With a Mentor Commented:
Example VBS code:

Sub CreateAfile
   Dim fso, MyFile
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
   MyFile.WriteLine("This is a test.")
   MyFile.Close
End Sub

If fso.FileExists(path) Then
   Response.Write ("Your file, '" & getname & "', has been created.")
End If

Open in new window

0
 
HKFueyAuthor Commented:
OK, I'm nearly there, I have created the text file but the part that checks if it exits crashes on line 6 with "Error number 424 Object required: 'fso'

Dim SavFil 
Dim fso, MyFile
SavFil = "C:\Temp\" & PurchaseOrder & ".txt"
msgbox SavFil

If fso.FileExists(SavFil) Then
   msgbox SavFil & " Already Created"
exit sub
End If

'Create file to flag order

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fso.CreateTextFile(SavFil, True)
   MyFile.WriteLine("This is a test.")
   MyFile.Close

Open in new window

0
 
HKFueyAuthor Commented:
Needed to move  Set fso = CreateObject("Scripting.FileSystemObject") further up in my code!!
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.