Common Dialog - default path

Is it possible to amend the following code so that a default path, perhaps contained in a hidden text box, can be used each time the dialog is opened.

Here is what I have now: (please note I had to retype this manually, database on different PC, so it could contain a typo but you will get the gist of what it does)

Private sub cmdBrowse_Click
On Error goto err_cmdBrowse_Click

Dialog1.CancelError = true
'set flags
Dialog1.flags = cdlOFNHideReadOnly
'set filters
Dialog1.Filter = "Text Files (*.doc)|*.doc"
'set default file name
me.dialog1.dialogTitle = "Select word document to be linked"
Dialog1.ShowSave
me!text78 = me!dialog1.FileName

error handling lines follow etc

Lets say I have another text box, ie txtDefaultPath, which has "G:\docs\Jan2000" as it's contents.  Can I have the dialog box automatically open to this folder when the browse button is clicked.

thanks for your help

LVL 2
josladAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
pacificdbConnect With a Mentor Commented:
joslad,

Yes, all you have to do is set the InitDir property, thus:

  Dialog1.InitDir = Me!txtDefaultPath

To set the default filename (perhaps you're looking for a specific file), use the following:

  Dialog1.FileName = "filename.txt"

Of course, this has to match the Filter property (which sets the default filetype extension).

By the way, it is always good practice to set the cdlOFNNoChangeDir flag when using the dialog control, to avoid your current directory being changed.

I hope this helps.


0
 
josladAuthor Commented:
Thanks pacificdb - seems to do the trick!

Thanks for your help.  much appreciated.
0
All Courses

From novice to tech pro — start learning today.