I'm using a FileDialog command to allow users to select a file from a certain folder. It's working, but I'd like to filter down to only files that contain the word "active". I tried .filters.add "active *", "*.csv", but I get files with other names that are also .csv. Eventually, this folder will be pretty full of files, so I'd like to make it easier for the user to find the file they need. As if I was typing "active" in the search box in File Explorer. Here's my code currently:
Function Get_File_Active()
'Declare a variable to contain FileDialog
Dim sMyPath As FileDialog
'Declare a variable to contain the path
Dim aPath As Variant
DoCmd.SetWarnings False
DoCmd.Hourglass True
' Set up the File Dialog.
Set sMyPath = Application.FileDialog(msoFileDialogFilePicker)
With sMyPath
' Do not allow users to make multiple selections in dialog box
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Select your Archived Active File"
' Clear out the current filters, and add your own. Looking for a file like "active 20211221.csv"
.Filters.Clear
.Filters.Add "active *", "*.csv"
'Go to the Archive folder.
.initialfilename = "K:\Customer Service Capacity Queue Data Tool\Queue Data Inputs\Archive"
'Set the text of the button Caption
.ButtonName = "Get Active File"
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
For Each aPath In .SelectedItems
'MsgBox aPath
'Import into Active table
DoCmd.OpenQuery "ACTIVE_DELETE"
DoCmd.TransferText acImportDelim, "active_import_spec_date", "active", aPath, False
Next aPath
Else
'Show if Canceled is selected in a message box
aPath = "No File Selected to Import."
MsgBox aPath
End If
End With
DoCmd.SetWarnings True
DoCmd.Hourglass False
'Gut check the upload numbers.
Dim MsgA, StyleA, TitleA, ResponseA
MsgA = "ACTIVE file was uploaded and contained " & DCount("*", "ACTIVE") & " records. A typical workday usually has around 70,000."
StyleA = vbOKOnly + vbInformation + vbDefaultButton1
TitleA = "IC1 File Uploads"
ResponseA = MsgBox(MsgA, StyleA, TitleA)
End Function
Function Get_File_Active()
'Declare a variable to contain FileDialog
Dim sMyPath As FileDialog
'Declare a variable to contain the path
Dim aPath As Variant
DoCmd.SetWarnings False
DoCmd.Hourglass True
' Set up the File Dialog.
Set sMyPath = Application.FileDialog(msoFileDialogFilePicker)
With sMyPath
' Do not allow users to make multiple selections in dialog box
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Select your Archived Active File"
' Clear out the current filters, and add your own. Looking for a file like "active 20211221.csv"
.Filters.Clear
.Filters.Add "active *", "*.csv"
'Go to the Archive folder.
.initialfilename = "K:\Customer Service Capacity Queue Data Tool\Queue Data Inputs\Archive"
'Set the text of the button Caption
.ButtonName = "Get Active File"
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
For Each aPath In .SelectedItems
'MsgBox aPath
'Import into Active table
DoCmd.OpenQuery "ACTIVE_DELETE"
DoCmd.TransferText acImportDelim, "active_import_spec_date", "active", aPath, False
Next aPath
Else
'Show if Canceled is selected in a message box
aPath = "No File Selected to Import."
MsgBox aPath
End If
End With
DoCmd.SetWarnings True
DoCmd.Hourglass False
'Gut check the upload numbers.
Dim MsgA, StyleA, TitleA, ResponseA
MsgA = "ACTIVE file was uploaded and contained " & DCount("*", "ACTIVE") & " records. A typical workday usually has around 70,000."
StyleA = vbOKOnly + vbInformation + vbDefaultButton1
TitleA = "IC1 File Uploads"
ResponseA = MsgBox(MsgA, StyleA, TitleA)
End Function