Private Sub cmdSelect_Click()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim strPath As String
' Set up the File Dialog. '
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
' Set default path which is users download folder
strPath = GetDownloadsFolder()
' Disable sunform in case form left enabled from a previous run.
Me.sfrmBankStatement.Form.AllowEdits = False
With fDialog
' Allow user to make multiple selections in dialog box '
.AllowMultiSelect = False
' Set the title of the dialog box. '
.Title = "Please select Bank Statement downloaded file"
' Clear out the current filters, and add our own.'
.Filters.Clear
.Filters.Add "CSV files", "*.csv"
.InitialFileName = strPath
' Show the dialog box. If the .Show method returns True, the '
' user picked at least one file. If the .Show method returns '
' False, the user clicked Cancel. '
If .Show = True Then
Me.txtFilename = .SelectedItems(1)
Else
MsgBox "You must select a filename!"
Me.txtFilename = ""
Exit Sub
End If
End With
' Now get that data
DoCmd.SetWarnings False
SetStatusBar ("Deleting old data .....")
DoCmd.RunSQL "DELETE * from TesttblBankStatement"
SetStatusBar ("Importing selected data")
DoCmd.TransferText acImportDelim, "Bank Statement Import Specification", "TesttblBankStatement", Me.txtFilename, True
DoCmd.SetWarnings False
SetStatusBar (" ")
' Now enable subform if file selected
Me.sfrmBankStatement.Form.AllowEdits = True
Me.sfrmBankStatement.Form.Requery
End Sub