I am trying to export a textfile (query) from an access application, but I need the filename to be unique for each time this occurs (following a standard format)
Many thanks for the advice, but can you tell me how I would specify that (if the export were within a macro, presumably I cant just put file+now().txt within the export filename field.
Regards
Phil.
ps (maybe I should have said that this needed to be an automtic repetitive process)
or something like that. In a macro? Sorry, never use them, I'm afraid they'll phase them out completely in the future. Maybe there's a macro expert reading this who can help.
You could have a textfile (lastfile.txt) located in the same folder that your trying to write to. Have this textfile contain the last number in the sequence.
Your export code could have the following setup...
Option Compare Database
Option Explicit
Function ExportQueryToFile()
On Error GoTo Error_ExportQueryToFile
'
' Variable Declaration
'
Const intSeqLen As Integer = 4 'The length of the sequential number at the end of each file
Const strDrivePath As String = "d:\temp\" 'The drive and path where output file should go
Dim intPos As Integer 'Use to identify the current position/length of reference
Dim intLastFile As Integer 'The last sequential number used as imported from lastfile.txt
Dim intNextFile As Integer 'The value representing the number to be used for export on this occasion
Dim strNextFile As String 'The string equivelant of intNextFile including pre-padded zero(s)
Dim strSeqFile As String 'The full path and filename of the Sequential Number generator
Dim FileIsOpen As Boolean 'Is the Input file open?
MsgBox "The maximum number of export files has been met.@Change the code of this program " _
& "to increase the constant variable known as@intSeqLen.", vbOKOnly + vbCritical, "Error: 9999"
Resume Exit_ExportQueryToFile
ElseIf Err.Number = 9998 Then
intLastFile = (CInt(InputBox("The " & strSeqFile & " will be created now. You need to specify what " _
& "the first sequential number will be. It must be less than " & (10 ^ intSeqLen) & ". Start numbering at...", _
strSeqFile & " not found!", 1)) - 1)
Resume New_ExportQueryToFile
Thanks shorty, and thank v much for all the documentation.
Now would I be a reeeal pain if I asked how I could get another application to import each of said files(to the same table)i.e. look for text files where the name is of a given format, and one by one import them.
I'll have to get back to you on monday, but basically, on specification of a file number (say 0345 input by user), you could run code to process the file: e.g.
if dir("d:\temp\file0345.txt" <> "" then
open text file
while to eof
read record
docmd.runsql("APPEND QUERY"
loop
close file
endif
If file exists, import record, and append values to table
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.