R
requeth
Ok, so I'm creating an onclick backup logfile that will run a query and
capture a record and write it to a text file before running an sql
update procedure to modify the database. I one function that runs to
see if the file exists or not. If it does not exist, the file is
created, and the data is written to the file. If the file already
exists (and this is the broken part), the file should be opened, and
the data appended, then the file should be closed. For some reason I am
receiving "Invalid procedure call or argument" when I attempt to run
the opentxtfile sub to append to the file. I have attached the code
below and put a >> where the error is flagging.
Option Compare Database
'myspec is the specification for output. To create this choose the
table/tables you will be exporting from and
'go to file: Export File. Choose save.
'Choose Advanced, change any settings you like and choose and choose
save as.
'Name specification, in this case as myspec.
Function output1() As String
DoCmd.TransferText acExportDelim, myspec, "query1",
"F:\Test1\Test2.txt"
End Function
Sub opentxtfile()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")a.Write "Hello world!"
a.Close
End Sub
Function FileExists() As String
'runs onclick to create a backup log.
Dim fso
Dim file As String
file = "F:\Test1\Test2.txt" 'log path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(file) Then
'if file doesent exist run output1 function to create file and populate
data
output1
Else
'if file exists run opentxtfile sub which appends data to the already
created logfile.
opentxtfile
End If
End Function
capture a record and write it to a text file before running an sql
update procedure to modify the database. I one function that runs to
see if the file exists or not. If it does not exist, the file is
created, and the data is written to the file. If the file already
exists (and this is the broken part), the file should be opened, and
the data appended, then the file should be closed. For some reason I am
receiving "Invalid procedure call or argument" when I attempt to run
the opentxtfile sub to append to the file. I have attached the code
below and put a >> where the error is flagging.
Option Compare Database
'myspec is the specification for output. To create this choose the
table/tables you will be exporting from and
'go to file: Export File. Choose save.
'Choose Advanced, change any settings you like and choose and choose
save as.
'Name specification, in this case as myspec.
Function output1() As String
DoCmd.TransferText acExportDelim, myspec, "query1",
"F:\Test1\Test2.txt"
End Function
Sub opentxtfile()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")a.Write "Hello world!"
a.Close
End Sub
Function FileExists() As String
'runs onclick to create a backup log.
Dim fso
Dim file As String
file = "F:\Test1\Test2.txt" 'log path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(file) Then
'if file doesent exist run output1 function to create file and populate
data
output1
Else
'if file exists run opentxtfile sub which appends data to the already
created logfile.
opentxtfile
End If
End Function