Final Solution to Application.FileSearch for 2007

DCrake

Remembered
Local time
Today, 13:55
Joined
Jun 8, 2005
Messages
8,626
This has been discussed to death but has a final relsolution been reached?

I want to use a filesearch in 2007 my previous code was

Code:
Dim Example As Integer
[COLOR="Red"]Dim dlg As FileDialog[/COLOR]
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
    .Title = "Select the database file to open"
    .AllowMultiSelect = False
    .Filters.Clear
    .Filters.Add "Access 2000/2003", "*.mdb", 1
    .Filters.Add "Access 2007/2010", "*.accdb", 2
    .Filters.Add "All Files", "*.*", 3
    If .Show = -1 Then
        StrFileName = .SelectedItems(1)
    End If
End With

However it falls over on the red line

I do not want to use the CommonDialog component but I want to be able to allow different filter types. Has anyone got a solution please.
 
Hi David,

I know FileSearch is a deprecated function in 2007+ but your code isn't using this feature. Unless

Looking at your code, I think you mean you want to streamline the file types available in the File Dialog box. If the declaration is failing then it will be a reference issue. You can use:

Dim dlg As Object
 
If you latebind dlg the you must supply a constant for msoFileDialogFilePicker.

Const msoFileDialogFilePicker = 3

JR
 
VbaINet

Have you a working example?
 
I haven't got 2007 on this machine but I will make one up when I get home later in the evening. Is the suggestion of dimensioning the variable as an Object not cutting it?
 
Oh by the way David, I tested your code in 2007 and it worked for me - both Object and FileDialog types.
 

Users who are viewing this thread

Back
Top Bottom