S
Steve F. via AccessMonster.com
I'm trying to import an Excel spreadsheet called dh.xls to an Access table
named tblprofilestage. But, I keep getting an error to check the path, but I
know the path is correct.
Can anyone help me with the code? Here it is:
Public Function ImpToAccess()
Dim dbPath As String
Dim gotTable As Boolean
gotTable = False
dbPath = InputBox("Enter Location of Spreadsheet" + Chr(13) + "(drive:\path\)
", "Location of Spreadsheet")
If dbPath <> "" Then
If Dir(dbPath + "dh.xls", vbNormal) <> "" Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97,
"tblProfileStage", dbPath + "dh.xls", , True
DoCmd.OpenQuery "qryAppendDH", acNormal, acEdit
DoCmd.DeleteObject acTable, "tblProfileStage"
MsgBox "Spreadsheet has been imported...", vbExclamation, "Import Data"
gotTable = True
End If
End If
If gotTable = False Then
MsgBox "No data was imported, please check your path...",
vbCritical, "Import Tables Fail"
ImportExcel = False
Else
MsgBox "Your data has been imported...", vbExclamation, "Import
Successful"
ImportExcel = True
End If
End Function
named tblprofilestage. But, I keep getting an error to check the path, but I
know the path is correct.
Can anyone help me with the code? Here it is:
Public Function ImpToAccess()
Dim dbPath As String
Dim gotTable As Boolean
gotTable = False
dbPath = InputBox("Enter Location of Spreadsheet" + Chr(13) + "(drive:\path\)
", "Location of Spreadsheet")
If dbPath <> "" Then
If Dir(dbPath + "dh.xls", vbNormal) <> "" Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97,
"tblProfileStage", dbPath + "dh.xls", , True
DoCmd.OpenQuery "qryAppendDH", acNormal, acEdit
DoCmd.DeleteObject acTable, "tblProfileStage"
MsgBox "Spreadsheet has been imported...", vbExclamation, "Import Data"
gotTable = True
End If
End If
If gotTable = False Then
MsgBox "No data was imported, please check your path...",
vbCritical, "Import Tables Fail"
ImportExcel = False
Else
MsgBox "Your data has been imported...", vbExclamation, "Import
Successful"
ImportExcel = True
End If
End Function