Friday, July 10, 2009

Import Excel file using VBA in Access.


'********** Component details ****************
' Add "Microsoft office 10.1 Object Library from Tools > Referance.
' Command2 as Browse Button
' Command3 as Import Button
' Text0 as Textbox
'*********************************************

Private Sub Command2_Click()
' For Get the traget file name along with path
On Error GoTo lb1
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Show
Text0.Value = fd.SelectedItems(1)
Exit Sub
lb1:
MsgBox "No File selected"
Text0.Value = Empty
End Sub


Private Sub Command3_Click()
' To import the targeted file for which path is stored in "Text0" Textbox
aa = InputBox("Please enter the 'Table Name'", "Table Name", "Tbl" & Format(Now, "hhmmss"))
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel, aa, Text0.Value, -1
End Sub


No comments:

Post a Comment