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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pacificdbCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
josladAuthor Commented:
Thanks pacificdb - seems to do the trick!

Thanks for your help.  much appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.