Importing a csv file and it keeps creating copy import error tables
I though by changing the HasFieldNames:=True it would ignore the error
Private Sub cmdImport_Click()
On Error Resume Next:
Dim db As DAO.Database
Set db = CurrentDb
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Const strFolder As String = "\\LT014\Users\dgriffin\Desktop\import\"
createNewDirectory (strFolder & "processed")
Const strPattern As String = "*.csv"
Dim strFile As String
strFile = Dir(strFolder & strPattern, vbNormal)
Do While Len(strFile) > 0
db.Execute "delete from tblimport"
If strFile <> "" Then
DoCmd.TransferText TransferType:=acImportDelim, TableName:="tblImport", FileName:=strFolder & strFile, HasFieldNames:=False
fso.MoveFile strFolder & strFile, strFolder & "processed\"
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "qry_Insert_New_Items"
DoCmd.OpenQuery "qry_Insert_New_items_detail"
DoCmd.SetWarnings True
strFile = Dir
Loop
db.Close
Set db = Nothing
Me.Requery
End Sub
I though by changing the HasFieldNames:=True it would ignore the error
Private Sub cmdImport_Click()
On Error Resume Next:
Dim db As DAO.Database
Set db = CurrentDb
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Const strFolder As String = "\\LT014\Users\dgriffin\Desktop\import\"
createNewDirectory (strFolder & "processed")
Const strPattern As String = "*.csv"
Dim strFile As String
strFile = Dir(strFolder & strPattern, vbNormal)
Do While Len(strFile) > 0
db.Execute "delete from tblimport"
If strFile <> "" Then
DoCmd.TransferText TransferType:=acImportDelim, TableName:="tblImport", FileName:=strFolder & strFile, HasFieldNames:=False
fso.MoveFile strFolder & strFile, strFolder & "processed\"
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "qry_Insert_New_Items"
DoCmd.OpenQuery "qry_Insert_New_items_detail"
DoCmd.SetWarnings True
strFile = Dir
Loop
db.Close
Set db = Nothing
Me.Requery
End Sub