John Wolfenstein
John Wolfenstein

Reputation: 141

MS Access FileDialog Filter doesn't work on original load

I have the following script code that filter and title setting don't work the first time I run the code, but subsequent uses it does.

Any suggestions?

Set f = Application.FileDialog(msoFileDialogFilePicker)

If f.Show = True Then

With f
    .Title = "Choose Excel File(s) to Import"
    .Filters.Clear
    .Filters.Add "Excel Files", "*.xlsx"
    .AllowMultiSelect = True

    For Each varfile In .SelectedItems
        MsgBox "IMPORTING: " & varfile
        tblImport = varfile
        DoCmd.TransferSpreadsheet acImport, 10, "Parts", tblImport, True
    Next varfile
End With

Upvotes: 1

Views: 401

Answers (1)

HansUp
HansUp

Reputation: 97101

Set the FileDialog properties before calling the Show method.

Set f = Application.FileDialog(msoFileDialogFilePicker)

With f
    .Title = "Choose Excel File(s) to Import"
    .Filters.Clear
    .Filters.Add "Excel Files", "*.xlsx"
    .AllowMultiSelect = True
    If .Show = True Then
        For Each varfile In .SelectedItems
            MsgBox "IMPORTING: " & varfile
            tblImport = varfile
            DoCmd.TransferSpreadsheet acImport, 10, "Parts", tblImport, True
        Next varfile
    End If
End With

Upvotes: 1

Related Questions