Castiel
Castiel

Reputation: 75

Refreshing form after importing data

Still new to access so not sure if this is even possible or if I should just add a separate button, basically I have written code to import excel documents and I need the form to refresh/requery once the import has been completed.

I've tried both me.refresh and me.requery however the form doesn't update.

Private Sub ImportBlacklist_Click()

Dim SelectedFile    As String
Dim FilePicker      As FileDialog
Dim SQLdelete       As String

Set FilePicker = Application.FileDialog(msoFileDialogFilePicker)
FilePicker.AllowMultiSelect = False
FilePicker.Filters.Add "Excel", "*.xls*", 1
FilePicker.InitialFileName = "C:\Users\"
FilePicker.Title = "Select Suppression List Location..."
FilePicker.Show

If FilePicker.SelectedItems.Count <> 0 Then
    SelectedFile = FilePicker.SelectedItems(1)

    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Blacklist", SelectedFile, True

    MsgBox ("Import Success")
End If

Exit Sub

Me.Requery

ErrorHandler:
MsgBox "There was an Error: " & Err & ": " & Error(Err)
End Sub

The import all works perfectly as intended, I just need it to update the form once the MsgBox has closed

Upvotes: 0

Views: 44

Answers (1)

Andre
Andre

Reputation: 27644

You have

Exit Sub

Me.Requery

Me.Requery would do the job, but it isn't executed because of Exit Sub before.

Switch the two lines.

Upvotes: 1

Related Questions