Hey all. Need a little assistance here. I originally found this code online somewhere and someone here at my office helped me to modify it. However now I need another modification and the most knowledgable person here is out for the weekend. So I'm hoping you guys can help me out.
The code goes out to a network drive and sweeps everything into one table in Access, then moves the file to a processed folder. I need to modify it so it includes the file name as a column in the table, which contains the date. I don't want the date the file is created because it can be off by a day, but the file name is always correct.
Here's my code. Can anyone point me in the right direction?
The code goes out to a network drive and sweeps everything into one table in Access, then moves the file to a processed folder. I need to modify it so it includes the file name as a column in the table, which contains the date. I don't want the date the file is created because it can be off by a day, but the file name is always correct.
Here's my code. Can anyone point me in the right direction?
Code:
Public Function Import_From_TEXT()
'Macro Loops through the specified directory (strPath)
'and imports ALL *.dat files to specified table in the Access
'Database.
Const strPath As String = "\\mynetworklocation\LetterOutbound\" 'Directory Path
Const strNewPath As String = "\\mynetworklocation\LetterOutbound\Processed\" 'new path to archive
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
Dim strOldName, strNewName As String
'Loop through the folder & build file list
strFile = Dir(strPath & "*.dat")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
Exit Function
End If
'cycle through the list of files & import to Access
'creating a new table
For intFile = 1 To UBound(strFileList)
DoCmd.TransferText acImportFixed, "dailyspecs", "tmpLetter_Files", strPath & strFileList(intFile), True
'strFilename = strFileList(intFile)
strOldName = strPath & strFileList(intFile)
strNewName = strNewPath & strFileList(intFile)
Name strOldName As strNewName
Next
MsgBox UBound(strFileList) & " Files were Imported"
End Function