ankitpaudel
09-28-2010, 10:12 PM
I am using this code for import excel file into table
when i use this code its delete all table but i don't want to delete other
tables and when i import excel files message will display filed name not
found how i know which file name fields are wrong how to fix it. i know this red highlighted code delete table i just want to delete record from specification table only please help
Dim dbs As DAO.Database
Dim i As Integer
Set dbs = CurrentDb
For i = dbs.TableDefs.Count - 1 To 0 Step -1
If Left(dbs.TableDefs(i).Name, 4) <> "MSys" _
And dbs.TableDefs(i).Name <> "tblSpecial1" _
And dbs.TableDefs(i).Name <> "tblSpecial2" Then
dbs.TableDefs.Delete dbs.TableDefs(i).Name
End If
Next i
Set dbs = Nothing
Const strPath As String = "c:\temp\" 'Directory Path
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
strFile = Dir(strPath & "*.xls")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
If intFile = 0 Then
MsgBox "No files found"
Exit Sub
End If
For intFile = 1 To UBound(strFileList)
DoCmd.TransferSpreadsheet acImport, , "tblTest", strPath & strFileList(intFile), _
True, "F!A1:AB8000"
Next
MsgBox UBound(strFileList) & " Files were Imported"
Edited 29-Sep-10 by geekgirlau. Reason: insert vba tags
Thanks in advance
ankit
when i use this code its delete all table but i don't want to delete other
tables and when i import excel files message will display filed name not
found how i know which file name fields are wrong how to fix it. i know this red highlighted code delete table i just want to delete record from specification table only please help
Dim dbs As DAO.Database
Dim i As Integer
Set dbs = CurrentDb
For i = dbs.TableDefs.Count - 1 To 0 Step -1
If Left(dbs.TableDefs(i).Name, 4) <> "MSys" _
And dbs.TableDefs(i).Name <> "tblSpecial1" _
And dbs.TableDefs(i).Name <> "tblSpecial2" Then
dbs.TableDefs.Delete dbs.TableDefs(i).Name
End If
Next i
Set dbs = Nothing
Const strPath As String = "c:\temp\" 'Directory Path
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
strFile = Dir(strPath & "*.xls")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
If intFile = 0 Then
MsgBox "No files found"
Exit Sub
End If
For intFile = 1 To UBound(strFileList)
DoCmd.TransferSpreadsheet acImport, , "tblTest", strPath & strFileList(intFile), _
True, "F!A1:AB8000"
Next
MsgBox UBound(strFileList) & " Files were Imported"
Edited 29-Sep-10 by geekgirlau. Reason: insert vba tags
Thanks in advance
ankit