Hello,

I am having trouble putting together some code that allows the user to select an excel file from their hard drive and then automatically import a set range of data into a new Access table.

Whenever I run the code, I get the following Run Time Error: 3051 ' Jet can't open the database because it is opened exclusively by another user or you need permission to read its data'.

Here is the code I am using:


Private Sub Command10_Click()
Dim Dlg As FileDialog
Dim txtFilePath As String
    
    Set Dlg = Application.FileDialog(msoFileDialogFilePicker)
    With Dlg
        .Title = "Select the USD_ATB file you want to import"
        .AllowMultiSelect = False
        If .Show = -1 Then
            txtFilePath = .InitialFileName
            DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblUSD", txtFilePath, False, "USD_ATB!C2:S150"
        Else
            Exit Sub
       End If
   End With
End Sub
If anyone can either help me tweak the code to make it work or propose another set of code to accomplish the same task, I would be very grateful. I appreciate everyone's time and effort. Thank you in advance.