Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting the default extension in clscommondialog

Status
Not open for further replies.

bravefool

Programmer
Jun 12, 2006
8
DE
I have created the following function to show a popup file selection window. It works great except for one thing, it does not accept the default string properly, or rather it ignores it. What I have tried to do is to pass "*.doc" as the default extension but it does not take. Does anyone have any ideas?

Thanks,

Phil

Here is the code:

Function DoComDialog(title As String, def_ext As String)

Rem This subroutine allows the user to pick a file and path from a popup menu
Dim commonDialog1 As New clsCommonDialog

With commonDialog1

.DialogTitle = title
.Filter = "Excel Spreadsheets (*.xls)|*.xls|Word Documents (*.doc)|*.doc|All files (*.*)|*.*"
.DefaultExt = def_ext
.ShowOpen
DoComDialog = .Filename

End With

End Function
 
the correct syntax for adding filters is:

.filter.add "name", "[delimited file types]"

this is assuming you are using the access native open dialog.

--------------------
Procrastinate Now!
 
Thanks for this. I am using comdlg32.dll. Maybe my mail wasn't clear, or perhaps I misunderstand you, but my question is concerning the default extension for the dialog box. I want to be able to select Word documents as being the initial filter. The filter selection dropdown is working as I have it...

Thanks again,

Phil
 
if you're using the windows native dialog, then the delimiter you need to use is vbNullChar

--------------------
Procrastinate Now!
 
It is this line that doesn't seem to be working:

commonDialog1.DefaultExt = def_ext

I set def_ext = "*.doc" and it still shows "*.xls" in the popup. Where and how would I apply vbNullChar?

Thanks a million!
 
by default, the default extension is the first one you put in your filter string...

however you can set it by putting in the extension WITHOUT the *.

ie.e def_ext = "DOC"

--------------------
Procrastinate Now!
 
it works fine for me...

are you sure it's not something else?

look at the methods for the library...

--------------------
Procrastinate Now!
 
Could it be that I need to set something else? FilterIndex perhaps? Did you use exactly the same code as me?
 
I did use a filter index...

--------------------
Procrastinate Now!
 
Ok. So now here comes a dumb question:

What do I need to set the FilterIndex to?

Can you show me the code you used that worked so I am sure I am not missing something?

Thanks again.
 
I set the filter index to 1

--------------------
Procrastinate Now!
 
I now have solved the problem. I got rid of the DefaultExt altogether and set the FilterIndex equal one of 3 constants which I defined to have the values 1,2 and 3. It simply takes the nth entry in the filter list. So in my example Word would be 2 and I pass a constant called defWord to my function.

Anyway, thanks again for all of your help!

Phil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top