Link to home
Start Free TrialLog in
Avatar of HKFuey
HKFueyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of Alex_W
Alex_W
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HKFuey

ASKER

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

Avatar of HKFuey

ASKER

Needed to move  Set fso = CreateObject("Scripting.FileSystemObject") further up in my code!!