INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

MS Help shows invalid usage?

MS Help shows invalid usage?

(OP)
Hi,

I'm trying to set the filters on the filedialog as per the help example..

Quote:

' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog

' Allow user to make multiple selections in dialog box
.AllowMultiSelect = True

' Set the title of the dialog box.
.Title = "Please select one or more files"

' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Access Databases", "*.MDB"
.Filters.Add "Access Projects", "*.ADP"
.Filters.Add "All Files", "*.*"


But when I use this syntax...

CODE

Set fd = Application.FileDialog(msoFileDialogSaveAs)

    If Not IsMissing(cFilters) Then
        With fd
            .Filters.Clear
            For Each vFilter In cFilters.keys
                .Filters.Add cFilters.Item(vFilter), vFilter
            Next
        End With
    End If 

.Filters.Clear errors with "Object doesn't support this property or method"

Any ideas why I'm getting this error that contradicts the MS help for this FileDialog object?

Thanks,
1DMF


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: MS Help shows invalid usage?

What were the results when you used "msoFileDialogFilePicker" rather than "msoFileDialogSaveAs"?

Duane
Hook'D on Access
MS Access MVP

RE: MS Help shows invalid usage?

The help file is pretty explicit:

Quote (Microsoft Access help file)

A run-time error will occur if the Filters property is used in conjunction with the Clear, Add, or Delete methods when applied to a Save As FileDialog object

RE: MS Help shows invalid usage?

(OP)

Quote:

The help file is pretty explicit:
I have no idea where you are getting that, my F1 help says nothing of the sort?

Quote:

Access 2010 Developer Reference > Access Object Model Reference > Application Object > Properties
Access Developer Reference
Application.FileDialog Property
Returns a FileDialog object which represents a single instance of a file dialog box. Read-only.
Syntax

expression.FileDialog(dialogType)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data Type Description
dialogType Required MsoFileDialogType An MsoFileDialogType constant that represents the type of dialog box.

Remarks


The msoFileDialogOpen and msoFileDialogSaveAs constants are not supported in Microsoft Access.


Example


This example illustrates how to use the FileFialog object to display a dialog box that allow the user to select one or more files. The selected files are then added to a listbox named FileList.

Visual Basic for Applications
Private Sub cmdFileDialog_Click()

' Requires reference to Microsoft Office 11.0 Object Library.

Dim fDialog As Office.FileDialog
Dim varFile As Variant

' Clear listbox contents.
Me.FileList.RowSource = ""

' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog

' Allow user to make multiple selections in dialog box
.AllowMultiSelect = True

' Set the title of the dialog box.
.Title = "Please select one or more files"

' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Access Databases", "*.MDB"
.Filters.Add "Access Projects", "*.ADP"
.Filters.Add "All Files", "*.*"

' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then

'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
Me.FileList.AddItem varFile
Next

Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub


© 2010 Microsoft Corporation. All rights reserved.



See Also
Application Object
Application Object Members

It does state : The msoFileDialogOpen and msoFileDialogSaveAs constants are not supported in Microsoft Access.

However, as they are simply enums I declared my own constant and it works fine?

Private Const msoFileDialogSaveAs As Integer = 2

According to the office enums : https://msdn.microsoft.com/en-us/library/office/ff...

2 = Save As Dialog

I'm confused!


@Duane I don't want to select an existing file per se, so that GUI is no good to me as it errors if you type your own filename stating it doesn't exist sad



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: MS Help shows invalid usage?

It is because of the type of filedialog you picked. If it was a "picker" it would work. Since it is a "saveas" it is not an option

RE: MS Help shows invalid usage?

Sorry I did not see Duane's post, which is correct. You get the same type of errors when working with different type of recordsets, because you can only do certain things depending on the type of recordset but the properties are all still visible.

RE: MS Help shows invalid usage?

Why would you look up the FileDialog object rather than the FileDialogFilters for help on a FileDialogFilters method?

Quote:

Access 2010 Developer Reference > Object Library Reference for Microsoft Office 2010 > Microsoft Office 2010 Object Model Reference > FileDialogFilters Object
Office Developer Reference
FileDialogFilters Object
A collection of FileDialogFilter objects that represent the types of files that can be selected in a file dialog box that is displayed using the FileDialog object.
Example


Use the Filters property of the FileDialog object to return a FileDialogFilters collection. The following code returns the FileDialogFilters collection for the File Open dialog box.

Visual Basic for Applications
Application.FileDialog(msoFileDialogOpen).Filters

Use the Add method to add FileDialogFilter objects to the FileDialogFilters collection. The following example uses the Clear method to clear the collection and then adds filters to the collection. The Clear method completely empties the collection; however, if you do not add any filters to the collection after you clear it, the "All files (*.*)" filter is added automatically.

Visual Basic for Applications
Sub Main()

'Declare a variable as a FileDialog object.
Dim fd As FileDialog

'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)

'Declare a variable to contain the path
'of each selected item. Even though the path is aString,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant

'Use a With...End With block to reference the FileDialog object.
With fd

'Change the contents of the Files of Type list.
'Empty the list by clearing the FileDialogFilters collection.
.Filters.Clear

'Add a filter that includes all files.
.Filters.Add "All files", "*.*"

'Add a filter that includes GIF and JPEG images and make it the first item in the list.
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1

'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the button.
If .Show = -1 Then

'Step through eachString in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems

'vrtSelectedItem is aString that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example displays the path in a message box.
MsgBox "Path name: " & vrtSelectedItem

Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With

'Set the object variable to Nothing.
Set fd = Nothing

End Sub

When changing the FileDialogFilters collection, remember that each application can only create an instance of a single FileDialog object. This means that the FileDialogFilters collection resets to its default filters whenever you call the FileDialog method with a new dialog box type. The following example iterates through the default filters of the SaveAs dialog box and displays the description of each filter that includes a Microsoft Excel file.

Visual Basic for Applications
Sub Main()

'Declare a variable as a FileDialogFilters collection.
Dim fdfs As FileDialogFilters

'Declare a variable as a FileDialogFilter object.
Dim fdf As FileDialogFilter

'Set the FileDialogFilters collection variable to
'the FileDialogFilters collection of the SaveAs dialog box.
Set fdfs = Application.FileDialog(msoFileDialogSaveAs).Filters

'Iterate through the description and extensions of each
'default filter in the SaveAs dialog box.
For Each fdf In fdfs

'Display the description of filters that include
'Microsoft Excel files
If InStr(1, fdf.Extensions, "xls", vbTextCompare) > 0 Then
MsgBox "Description of filter: " & fdf.Description
End If
Next fdf

End Sub


Note
A run-time error will occur if the Filters property is used in conjunction with the Clear, Add, or Delete methods when applied to a Save As FileDiaog object. For example,
Application.FileDialog(msoFileDialogSaveAs).Filters.Clear

will result in a run-time error.

© 2010 Microsoft Corporation. All rights reserved.


RE: MS Help shows invalid usage?

(OP)

Quote:

Why would you look up the FileDialog object rather than the FileDialogFilters for help on a FileDialogFilters method

Because filedialogfilters in not a method it is a property to a collection according to the filediolog help

I wanted to find out info on the filedialog, so I highlighted it and pressed F1 and got the help that implied the filedialogfilters collection could be augmented.

hey ho , no biggie , just wondered why the help implied the collection was available yet I was getting an error.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: MS Help shows invalid usage?

Sorry, yes, typo, FileDialogFilters object

>it is a property to a collection according to the filediolog help

No, no Filters is a property. That property contains a FileDialogFilters object

But I appreciate the fact that Microsoft's Office developer references are nowhere near as good (or accurate) as they used to be (e.g the example on the actual FileDialogFilters.Clear method page doesn't actually include an example of the Clear method - well it couldn't do, since it uses the SaveAs dialog for the example. Shoddy, very shoddy)

Oh, and if you add a reference to Microsoft Office to your project, you'll find msoFileDialogSaveAs magically becomes available ...

RE: MS Help shows invalid usage?

(OP)
>> No, no Filters is a property. That property contains a FileDialogFilters object

Oh, the docs say it is a property to a collection, not a FileDialogFilters class object, but yeah, all a bit confusing and not very helpful, which is why I come to TT to ask the experts winky smile

>> Oh, and if you add a reference to Microsoft Office to your project, you'll find msoFileDialogSaveAs magically becomes available ...

But that then messes with multiple office versions and late bindings doesn't it?

I do hate the fact that to get things to not be version bound, you don't reference the library, but then that means you get no intelisense banghead



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: MS Help shows invalid usage?

>But that then messes with multiple office versions and late bindings doesn't it?

Yes, yes it does.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close