• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

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?
0
HKFuey
Asked:
HKFuey
  • 2
1 Solution
 
Alex_WCommented:
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now