Private Sub cmdImportLogs_Click()
Dim fd As FileDialog
Dim strImportTable As String
Dim strImportSpec As String
Dim vrtSelectedItem As Variant 'Variable to contain selected path of the file(s)
Dim intTotal As Integer
Dim intCount As Integer
Dim strMsg As String
Dim strTitle As String
Dim strResponse As String
Dim intProgress As Integer ' Used for Progress Bar
Dim varRetVal As Variant ' Used for Progress Bar
strImportTable = "tblPlayerDataImport"
strImportSpec = "Player_Import_Spec"
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Use a With...End With block to reference the FileDialog object.
With fd
'Allow the user to select multiple files.
.AllowMultiSelect = True
.Filters.Add "Text Files", "*.txt", 1
.Title = "Select All Player Logs to import..."
'Use the Show method to display the File Picker dialog box and return the user's action.
'If the user presses the action button...
If .Show = -1 Then
'Start the count for the progress bar and check to make sure the
'appropriate number of files have been selected
intTotal = .SelectedItems.Count
'Set up the dialog box before finally importing the files
strMsg = "A total of " & intTotal & " files will be imported"
strTitle = "Total Files To Be Imported"
strResponse = MsgBox(strMsg, vbOKCancel, strTitle)
'Check to make sure the proper number of files will be imported
If strResponse = vbCancel Then
MsgBox "I will exit and not import the files.", vbOKOnly
Exit Sub
Else
End If
'Initialize the progress meter.
intCount = 0
varRetVal = SysCmd(acSysCmdInitMeter, "Importing Files...", intTotal)
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
'Increment the progress bar
varRetVal = SysCmd(acSysCmdUpdateMeter, intCount)
'Import the file using the assigned ImportSpec and ImportTable
DoCmd.TransferText acImportDelim, strImportSpec, strImportTable, vrtSelectedItem, False
'Increment the counter
intCount = intCount + 1
Next
'If the user presses Cancel...
Else
MsgBox "No Files were imported!", vbOKOnly, "Player Logs Import Status"
End If
End With
'Kill the progress bar
varRetVal = SysCmd(acSysCmdRemoveMeter)
'Set the object variable to Nothing.
Set fd = Nothing
varRetVal = SysCmd(acSysCmdClearStatus)
End Sub