Good Morning!
I am attempting to automate the import of a .csv file from a given directory and copy and append it to another table in a different layout. Below is my code. The error that i'm getting is it can't fine the copyobject in the database...any ideas on how th do this?
Option Compare Database
Option Explicit
Function DoImportandAppend()
Dim strPathFile As String
Dim strFile As String
Dim strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
' Change this next line to True if the first row in CSV worksheet
' has field names
blnHasFieldNames = False
' Replace C:\Users\u8201332\Desktop\New folder with the new path to the folder that
' contains the CSV files
strPath = "C:\Users\u8201332\Desktop\HRC folder\"
' Replace tablename with the real name of the table into which
' the data are to be imported
strFile = Dir(strPath & "*.csv")
Do While Len(strFile) > 0
strTable = Left(strFile, Len(strFile) - 4)
strPathFile = strPath & strFile
DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames
' Uncomment out the next code step if you want to delete the
' EXCEL file after it's been imported
DoCmd.SetWarnings False
DoCmd.CopyObject "", "tblhrc", acTable, "strpath & strFile"
DoCmd.OpenQuery "qryHRCflatfile", acViewNormal, acAdd
DoCmd.OpenQuery "qryappHRCdata", acViewNormal, acAdd
' Kill strPathFile
strFile = Dir()
Loop
End Function
Thanks!