Import Excel to Access 2010

billmark

Registered User.
Local time
Today, 12:53
Joined
Mar 28, 2012
Messages
25
Hi
I am using Access and Excel 2010.
1.I created a table with 15 fields in Access with the Primary Key
2.Excel file is created with 16 columns (1st column is blank for the Primary Key)
3.I used the Import function to import to Access. I works
4.I wrote VB to import but it fails using the same excel file
5.Here is my code and please help to identify where is the break:
QUOTE
Private Sub btbImportspreadsheet_Click()
Dim strsql As String
Dim fso As New FileSystemObject

If Nz(Me.txtFileName, "") = "" Then
MsgBox ("Please select a file!")
Exit Sub
End If

strsql = "delete * from tblFRT;"
DoCmd.SetWarnings False
DoCmd.RunSQL strsql
DoCmd.SetWarnings True

If fso.FileExists(Nz(Me.txtFileName, "")) Then

ExcelImport.ImportExcelSpreadsheet Me.txtFileName, "tblFRT"

Else
MsgBox ("File not found!")


End If

End Sub
UNQUOTE
 
Try something like this:

DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel12Xml,"tblFRT","C:\YourFullFolderPath\YourFileName.xlsx",True

Cheers!
Goh
 

Users who are viewing this thread

Back
Top Bottom