Dear all,
I am trying to import an excel sheet (with the exactly same format / structure) into access database by using one button created in Form. Not sure how should I go about it, if i want to
1. Import and add the records into tables without deleted the previous records.
2. Replace Field1 if the new records matched.
The following is the code I am using...
Private Sub Command11_Click()
Dim myfile As String, sql As String
Dim db As Database, rs As Recordset, rs_target As Recordset
Set db = DBEngine(0)(0)
myfile = OpenFile("c:\", "xls", "*.xls", 0)
If myfile = "" Then
End
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Tbl_Import"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Tbl_Import", myfile ', , "Importfile!"
Set rs = db.OpenRecordset("Tbl_Import")
DoCmd.SetWarnings True
MsgBox "File has been imported "
End Sub
I am trying to import an excel sheet (with the exactly same format / structure) into access database by using one button created in Form. Not sure how should I go about it, if i want to
1. Import and add the records into tables without deleted the previous records.
2. Replace Field1 if the new records matched.
The following is the code I am using...
Private Sub Command11_Click()
Dim myfile As String, sql As String
Dim db As Database, rs As Recordset, rs_target As Recordset
Set db = DBEngine(0)(0)
myfile = OpenFile("c:\", "xls", "*.xls", 0)
If myfile = "" Then
End
End If
DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Tbl_Import"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Tbl_Import", myfile ', , "Importfile!"
Set rs = db.OpenRecordset("Tbl_Import")
DoCmd.SetWarnings True
MsgBox "File has been imported "
End Sub