dSurvivalist
Registered User.
- Local time
- Today, 18:44
- Joined
- Apr 27, 2010
- Messages
- 21
Hello everyone,
I have a problem with importing text files with an existing specification.
My specification works well if i import a file manually, but i also use a code to import multiple files (.txt) with a criteria which is to be found in below code.
The code i acquired is importing the files but not the first lines of them. my .txt file structure is quite simple, and identical to each other. i need it to include also the first line of the texts, and add this line in a field in each records until another file begins to import. In other words, the date in reds below, has to be in each record as Field2. because each files first lines have different dates. the text files layout is like below;
1st File:
VPLHDREAAFB 20100423
VPLISTAN0AT0363704S41 3K305 AA 001.00000
VPLISTAN0AT0363706E5Q 6A228 BD 001.00000
VPLISTAN0AT0363706G9N 11000 AB 001.00000
VPLISTAN0AT0363706S43 7M125 BB 001.00000
..........
2nd File
VPLHDREAAFB 20100425
VPLISTAN0AT0363709T16 4B435 AB 001.00000
VPLISTAN0AT0363709T16 5E211 AC 001.00000
VPLISTAN0AT0363709T16 5E292 AD 001.00000
VPLISTAN0AT0363709T16 9D289 AC 001.00000
..........
and so on...
this is the code i use,
Function Load_Attendance_Data()
Dim NextFile, ImportFile, FileCriteria, ctr As Variant
Dim DB_Path, Folder As Variant
' get the DB path
DB_Path = "C:\Users\Q\Desktop\FTP\"
Folder = ""
FileCriteria = "C:\Users\Q\Desktop\FTP\" & "VPL*.txt"
' create field with path and filename to import MAKE THIS READ ALL files that start with 'VPL'
NextFile = Dir(FileCriteria)
' Check we have something to import
If NextFile = "" Then
MsgBox "No files to import", , "Error"
Exit Function
End If
ctr = 0
' Import each file that meets the criteria 'VPL*.txt'
While NextFile <> ""
' count files imported
ctr = ctr + 1
' add the path to the returned filename
ImportFile = DB_Path & Folder & NextFile
' Import file into table
DoCmd.TransferText acImport, "VPL", "VPL", ImportFile, True
' get another file if it exists
NextFile = Dir()
Wend
MsgBox ctr & " files imported", , "VPL"
End Function
I have a problem with importing text files with an existing specification.
My specification works well if i import a file manually, but i also use a code to import multiple files (.txt) with a criteria which is to be found in below code.
The code i acquired is importing the files but not the first lines of them. my .txt file structure is quite simple, and identical to each other. i need it to include also the first line of the texts, and add this line in a field in each records until another file begins to import. In other words, the date in reds below, has to be in each record as Field2. because each files first lines have different dates. the text files layout is like below;
1st File:
VPLHDREAAFB 20100423
VPLISTAN0AT0363704S41 3K305 AA 001.00000
VPLISTAN0AT0363706E5Q 6A228 BD 001.00000
VPLISTAN0AT0363706G9N 11000 AB 001.00000
VPLISTAN0AT0363706S43 7M125 BB 001.00000
..........
2nd File
VPLHDREAAFB 20100425
VPLISTAN0AT0363709T16 4B435 AB 001.00000
VPLISTAN0AT0363709T16 5E211 AC 001.00000
VPLISTAN0AT0363709T16 5E292 AD 001.00000
VPLISTAN0AT0363709T16 9D289 AC 001.00000
..........
and so on...
this is the code i use,
Function Load_Attendance_Data()
Dim NextFile, ImportFile, FileCriteria, ctr As Variant
Dim DB_Path, Folder As Variant
' get the DB path
DB_Path = "C:\Users\Q\Desktop\FTP\"
Folder = ""
FileCriteria = "C:\Users\Q\Desktop\FTP\" & "VPL*.txt"
' create field with path and filename to import MAKE THIS READ ALL files that start with 'VPL'
NextFile = Dir(FileCriteria)
' Check we have something to import
If NextFile = "" Then
MsgBox "No files to import", , "Error"
Exit Function
End If
ctr = 0
' Import each file that meets the criteria 'VPL*.txt'
While NextFile <> ""
' count files imported
ctr = ctr + 1
' add the path to the returned filename
ImportFile = DB_Path & Folder & NextFile
' Import file into table
DoCmd.TransferText acImport, "VPL", "VPL", ImportFile, True
' get another file if it exists
NextFile = Dir()
Wend
MsgBox ctr & " files imported", , "VPL"
End Function