Hi;
I have a function that I created with a lot of help. It creates an array from files in a specified directory, dumps these filenames into an Access table, renames each file with the correct extension and then imports each file. After this I have some cleanup queries.
The original goal of this process is to rename and import files on a weekly basis through a form. File date and import date would be assessed at the time that the file is renamed and imported. This part works perfect.
Here is the problem, there are appx 250 files from the past year that I need imported, which is why I have the array. But I need the filename attached to the group of records, and the date that it was imported into the PC. Can this be done? I tried doing this one by one, but every time I mess up, I have to start from the beginning.
Please help.
Here’s is the code for the array.
Function M_ALL_LOANSA()
Dim SQL As String
Dim DirectoryFiles() ' Array that contains dir listing
Dim count
ffile = DIR("C:\WINPATH\RECEIVE-BILL\E3*.REC")
Do While ffile <> ""
If ffile <> "" Then
ReDim Preserve DirectoryFiles(count)
DirectoryFiles(count) = ffile
count = count + 1
End If
ffile = DIR()
Loop
DoCmd.SetWarnings False
For Each itm In DirectoryFiles
TMP1 = Split(itm, ".")
SQL = "INSERT INTO FILENAMES (FILENAME) VALUES ('" & TMP1(0) & "')"
DoCmd.RunSQL SQL
FileCopy "c:\winpath\receive-bill\" & itm, "C:\WINPATH\receive-bill\" & TMP1(0) & ".txt"
DoCmd.TransferText acImportFixed, "hesc-down Import Specification", "ALL-LOANS", "C:\WINPATH\receive-bill\" & TMP1(0) & ".txt", False, ""
'DoCmd.OpenQuery "Q-EMPTY OUT FILENAMES", acViewNormal, acEdit
'DoCmd.Close acQuery, "Q-EMPTY OUT FILENAMES"
' CLEAN ALL LOANS
DoCmd.OpenQuery "Q-CLEAN ALL LOANS", acViewNormal, acEdit
DoCmd.Close acQuery, "Q-CLEAN ALL LOANS"
' APPEND TO ALL LOANS FORMATED
DoCmd.OpenQuery "Q-ALL LOANS APPEND TABLE", acViewNormal, acEdit
DoCmd.Close acQuery, "Q-ALL LOANS APPEND TABLE"
DoCmd.OpenQuery "Q-ALL LOANS EMPTY OUT TABLE", acViewNormal, acEdit
DoCmd.Close acQuery, "Q-ALL LOANS EMPTY OUT TABLE"
Next
M_ALL_LOANS_Exit:
Exit Function
M_ALL_LOANS_Err:
MsgBox Error$
Resume M_ALL_LOANS_Exit
End Function
I have a function that I created with a lot of help. It creates an array from files in a specified directory, dumps these filenames into an Access table, renames each file with the correct extension and then imports each file. After this I have some cleanup queries.
The original goal of this process is to rename and import files on a weekly basis through a form. File date and import date would be assessed at the time that the file is renamed and imported. This part works perfect.
Here is the problem, there are appx 250 files from the past year that I need imported, which is why I have the array. But I need the filename attached to the group of records, and the date that it was imported into the PC. Can this be done? I tried doing this one by one, but every time I mess up, I have to start from the beginning.
Please help.
Here’s is the code for the array.
Function M_ALL_LOANSA()
Dim SQL As String
Dim DirectoryFiles() ' Array that contains dir listing
Dim count
ffile = DIR("C:\WINPATH\RECEIVE-BILL\E3*.REC")
Do While ffile <> ""
If ffile <> "" Then
ReDim Preserve DirectoryFiles(count)
DirectoryFiles(count) = ffile
count = count + 1
End If
ffile = DIR()
Loop
DoCmd.SetWarnings False
For Each itm In DirectoryFiles
TMP1 = Split(itm, ".")
SQL = "INSERT INTO FILENAMES (FILENAME) VALUES ('" & TMP1(0) & "')"
DoCmd.RunSQL SQL
FileCopy "c:\winpath\receive-bill\" & itm, "C:\WINPATH\receive-bill\" & TMP1(0) & ".txt"
DoCmd.TransferText acImportFixed, "hesc-down Import Specification", "ALL-LOANS", "C:\WINPATH\receive-bill\" & TMP1(0) & ".txt", False, ""
'DoCmd.OpenQuery "Q-EMPTY OUT FILENAMES", acViewNormal, acEdit
'DoCmd.Close acQuery, "Q-EMPTY OUT FILENAMES"
' CLEAN ALL LOANS
DoCmd.OpenQuery "Q-CLEAN ALL LOANS", acViewNormal, acEdit
DoCmd.Close acQuery, "Q-CLEAN ALL LOANS"
' APPEND TO ALL LOANS FORMATED
DoCmd.OpenQuery "Q-ALL LOANS APPEND TABLE", acViewNormal, acEdit
DoCmd.Close acQuery, "Q-ALL LOANS APPEND TABLE"
DoCmd.OpenQuery "Q-ALL LOANS EMPTY OUT TABLE", acViewNormal, acEdit
DoCmd.Close acQuery, "Q-ALL LOANS EMPTY OUT TABLE"
Next
M_ALL_LOANS_Exit:
Exit Function
M_ALL_LOANS_Err:
MsgBox Error$
Resume M_ALL_LOANS_Exit
End Function