Hello,
I have tons of CSV logs created daily, need to be able to specify a date range i.e. "9/20/2021 - 9/23/2021" and open all the files created during this period.
Import them into an access 2016 table
This is the code I have pieced together from the web; however, I am unable to get it to work as it hangs up on the file open & import portion of it.
NOTE: I am looking for a method to accomplish this, so if you have a better way please do share
Thank you so much for your time
UPDATE: Was "given" this code and it imports all the CSV files into a single table; however, got hanged up on the datecatreated check to force the import based on the two dates only
PS: apologies this is cross posted as well at vbaexpress.com
I have tons of CSV logs created daily, need to be able to specify a date range i.e. "9/20/2021 - 9/23/2021" and open all the files created during this period.
Import them into an access 2016 table
This is the code I have pieced together from the web; however, I am unable to get it to work as it hangs up on the file open & import portion of it.
NOTE: I am looking for a method to accomplish this, so if you have a better way please do share
Thank you so much for your time
UPDATE: Was "given" this code and it imports all the CSV files into a single table; however, got hanged up on the datecatreated check to force the import based on the two dates only
Code:
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String, strBrowseMsg As String
Dim blnHasFieldNames As Boolean
blnHasFieldNames = True
strBrowseMsg = "Select the folder that contains the CSV files:"
strPath = "E:\OP60\"
If strPath = "" Then
MsgBox "No folder was selected.", vbOK, "No Selection"
Exit Sub
End If
strTable = "tableData"
'*********************
Me.txt_Start_Date = "9/16/21"
Me.txt_Start_Date2 = "9/17/21"
'*********************
strFile = Dir(strPath & "\*.CSV")
Do While Len(strFile) > 0
strPathFile = strPath & "\" & strFile
'************************ERRORS HERE DO NOT KNOW HOW TO CHECK FOR DATECREATED :(
If strFile.DateCreated > (txt_Start_Date - 1) And strFile.DateCreated < (txt_Start_Date2 + 1) Then
'***********************
DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames
strFile = Dir()
Loop
PS: apologies this is cross posted as well at vbaexpress.com
Last edited: