Kamis, 02 Agustus 2012

[MS_AccessPros] Import Excel spreadsheet into Access

 

I copied the body of code from a book to use it for importing Excel files, when I ran it, it stopped at the line ".Filters.Add "Excel", "*.xlsx; *.xls", 1" . The error it gives out is "438 Object doesn't support this property or method".

I thought it was version problem, but the version of Access that I am using is Access 2007, so does the code that I copied from is Access VBA 2007. What's mistake did I make?

Private Sub cmdImport2_Click()
On Error GoTo ErrorHandler
Dim strFilePath As String
strFilePath = "C:\TempTestOnly\IDnumber.xlsx"

Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
With dlg
.Title = "Select the Excel file to import"
.AllowMultiSelect = False
'.Filters.Clear
.Filters.Add "Excel", "*.xlsx; *.xls", 1
.Filters.Add "All Files", "*.*", 2
.InitialFileName = strFilePath
If .Show = True Then
strFilePath = .SelectedItems(1)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "IDNumber", strFilePath, True
Else
GoTo ExitProcedure
End If
End With
ExitProcedure:
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbNewLine & Err.Description
Resume ExitProcedure
End Sub

Phucon

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar