Tuesday 23 May 2017

Import Access file through button in VBA MS Access

Private Sub Command2_Click()
Dim db As DAO.Database
Set db = CurrentDb
Const msoFileDialogFilePicker As Long = 3
Dim objDialog As Object
Set objDialog = Application.FileDialog(msoFileDialogFilePicker)
With objDialog
    .AllowMultiSelect = False
    .Show
    If .SelectedItems.Count = 0 Then
        MsgBox "!! No file selected.Please Select One !!"        
    Else
    For Each vrtSelectedItem In .SelectedItems
                FileName = vrtSelectedItem
               DoCmd.TransferDatabase acImport, "Microsoft Access", FileName, acTable, "Process", "Import_process", False
            Next
    End If
End With
END SUB

No comments:

Post a Comment