FileDialog not filtering files (1 Viewer)

jaryszek

Registered User.
Local time
Today, 05:40
Joined
Aug 25, 2016
Messages
756
Hi,

i am using code like:

Code:
sub test

Const partialName   As String = "OsServerRestriction"
Const partialExt   As String = "*.csv"
Dim fd As Object
Set fd = Application.FileDialog( _
         DialogType:=3)
Dim fileName As String
 
With fd
        
         .Title = "Select " & partialName & " File"
        .initialfilename = "E:\VnomicRep\Master_Workbook-Microsoft\Azure_Workbook\ImportData"
        
          With .Filters
            .Clear
            .Add partialName, partialExt
        End With

        If .Show Then
            selectFile = .SelectedItems(1)
        Else
            MsgBox "Cancelled by user"
            End
        End If
    End With
 
    Set fd = Nothing

    CurrentDb.Execute "DELETE * FROM Temp_SoftwareComponentsOses", dbFailOnError
    DoCmd.TransferText transferType:=acImportDelim, TableName:="Temp_SoftwareComponentsOses", SpecificationName:="Temp_SoftwareComponentsOses", fileName:=selectFile, hasfieldnames:=True
    MsgBox "Loaded!"

End Sub

and instead only one file matching the pattern i have all files:


Can anybody help ?
Why this is happening? Why this is not filtering?

Best,
Jacek
 

Attachments

  • Screenshot_14.jpg
    Screenshot_14.jpg
    68.4 KB · Views: 638

nhorton79

Registered User.
Local time
Tomorrow, 00:40
Joined
Aug 17, 2015
Messages
147
Maybe try using a wildcard, which might then restrict the selection.

Just guessing but could try:

Code:
.initialfilename = "E:\VnomicRep\Master_Workbook-Microsoft\Azure_Workbook\ImportDat?.xls"



Sent from my iPhone using Tapatalk
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:40
Joined
May 7, 2009
Messages
19,227
or

.InitialFileName = "E:\VnomicRep\Master_Workbook-Microsoft\Azure_Workbook\ImportData\" & partialName & "*"
 

nhorton79

Registered User.
Local time
Tomorrow, 00:40
Joined
Aug 17, 2015
Messages
147
or

.InitialFileName = "E:\VnomicRep\Master_Workbook-Microsoft\Azure_Workbook\ImportData" & partialName & "*"



Good spotting Arnel.

I didn’t look too closely at his image to see what folders / files he was looking at.
Though ImportData was the file name.


Sent from my iPhone using Tapatalk
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:40
Joined
Feb 19, 2013
Messages
16,601
not clear what you mean by filtering - do you mean the initial file name? or the filter?

if the former, you need to add .csv to the end of the initialfile name - at the moment it is looking for a folder

if you mean it should be looking for files in a folder called importdata then you need to include as \ after importdata

if you are looking for all .csv files that start with 'importdata' in the Azure_Workbook folder, include a * after importdata

if you are looking for a file which is not a .csv file, change your filter
 

jaryszek

Registered User.
Local time
Today, 05:40
Joined
Aug 25, 2016
Messages
756
Ok thank you Guys.

Basically what i want to do is:
1. Allow user to select his own folder and in this folder to select file name with pattern.

Arnelgp methos is working only in specified path - i want to do this path dynamic.
How to do this?

Best,
Jacek
 

jaryszek

Registered User.
Local time
Today, 05:40
Joined
Aug 25, 2016
Messages
756
Ok thank you Guys.

Basically what i want to do is:
1. Allow user to select his own folder and in this folder to select file name with pattern.

Arnelgp method is working only in specified path - i want to do this path dynamic and allow user to choose path. And in folder pointed by user should be only one filtered file based on pattern.
How to do this?

Best,
Jacek
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:40
Joined
Feb 19, 2013
Messages
16,601
dynamic how? with a username? e.g.

.InitialFileName = "E:\VnomicRep\Master_Workbook-Microsoft\Azure_Workbook\ImportData" & environ("Username") & "" & partialName & "*"
 

jaryszek

Registered User.
Local time
Today, 05:40
Joined
Aug 25, 2016
Messages
756
Cj_London, thanks!

Assume that you have "E:\VnomicRep\Master_Workbook" folder path and there is your file.

If you will provide initialName like above you will not see the files in this folder...Because chosen path by user is different then in InitialFileName...

Jacek
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:40
Joined
Feb 19, 2013
Messages
16,601
Not sure if you are asking a question -if you are, provide some examples and the path you would actually require for several users - or are they all

"E:\VnomicRep\Master_Workbook\username"

or do you mean

"E:\Username\VnomicRep\Master_Workbook"

or something else?
 

jaryszek

Registered User.
Local time
Today, 05:40
Joined
Aug 25, 2016
Messages
756
Hi,

thank you!

something else, i do not want to provide my path.
I want user to get specific file from folder pointed by user.

And user will point to specific folder and see csv file "OsServerRestriction.csv" because of pattern.

But i do not want to provide path. User should choose folder and only if there exists OsServerRestriction.csv it should be visible.

Best,
Jacek
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:40
Joined
Feb 19, 2013
Messages
16,601
So far as I know that can't be done. Filedialog can

specify an initial filepath, which you don't want
specify a file type, which you don't want
specify what a file name is, which you do want, but only as part of the initial filepath which the user can then change anyway

Suggest try

.InitialFileName = "OsServerRestriction.csv"

that should then open to whatever folder the user last used and they will need to navigate to the correct folder.

But as stated above the user can change this value
 

Users who are viewing this thread

Top Bottom