Loop through files in a folder based on date

creyn

Board Regular
Joined
Sep 16, 2016
Messages
127
I am trying to loop through Files in Folder based upon date that is entered in the Form. Below is the code I am using. I am having an issue with getting the files to be visible. Anyone help is greatly appreciated.

With fDialog
.Title = ""
.AllowMultiSelect = False
Intialfilename = ""

If IsNull(Me.Text6.Value) Then
MsgBox "Date cannot be empty. Please select date in order to proceed with this process."
ElseIf .Show = True Then
varfile = .SelectedItems(1) & "*\data*\ " & Me.Text6.Value
strFolder = varfile
Else
rtn = SysCmd(4, "Action aborted by user")
Exit Sub
End If
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Not sure what you mean by not being visible. Not visible when you provide a date? What if you don't provide a date?
The way your code is written, if there is a date, I think all of the part between the If IsNull(Me.Text6...) and its End If won't run.
This should come before you even present the dialog
Code:
If IsNull(Me.Text6.Value) Then
      MsgBox "Date cannot be empty.  Please select date in order to proceed with this process."
 Exit Sub (or Function as the case may be)
End If
That way, if there is no date, the dialog doesn't show AND the code exits. If there is a date, the IF date part is not processed, then the dialog opens. You deal with the dialog as needed after validating inputs from the form are in fact, there.
As for testing for null, when you get this working, type a space or two in the date control and let me know what happens when you perform the operation.
 
Last edited:
Upvote 0
This is what I mean it is not visible. When I look at the variable, varfile, the name of the file is not seen. I am looking to bring in the file name. I hope what I am saying makes some sort of sense?

?varfile
S:\zCorey\TDD Testing Folder*\data*\* 11/14/2016
 
Upvote 0
?varfile
S:\zCorey\TDD Testing Folder*\data*\* 11/14/2016


that's not a valid file name so I'm confused. No such file should exist or can exist
 
Upvote 0
Yes, that file name is not valid. So I changed the code and this is what I am getting now.

?varfile
S:\zCorey\TDD Testing Folder*\data\fof*

I am having an issue with the getting the file names that match that criteria to show. Can you tell me what I am doing wrong? Below is the code I am using.

Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = ""
.AllowMultiSelect = False
InitialFileName = ""

If IsNull(Me.Text6.Value) Then
MsgBox "Date cannot be empty. Please select date in order to proceed with this process."
ElseIf .Show = True Then
varfile = .SelectedItems(1) & "*\data" & "fof*"
strFolder = varfile
Else
rtn = SysCmd(4, "Action aborted by user")
Exit Sub
End If
 
Upvote 0
I haven't seen that before (i.e., using this in access:

Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)


but anyway, its apparently giving you a folder picker, not a file picker. What are you trying to do?
 
Upvote 0
I am trying to loop through the files that are in the folder. The reason I am using the msoFileDialogFolderPicker is because there are several folders that contains files.
 
Upvote 0
So, are you picking one of the folders, then?
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,938
Members
451,730
Latest member
BudgetGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top