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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog - InitDir property 3

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
On the open/save file dialog, I am setting the InitDir property. Does this just control the folder to which the user is directed on the first call to the dialog and subsequent calls return to whatever folder the user last navigated to? That's certainly the way it seems to behave.

If so, is there a way of overriding this - i.e. forcing the user to start from the same folder every time?

The problem I have is that I use a single dialog control for the entire application and want to look for different file types in different places according to context, so I don't want to go looking for graphics files in the same location that the user last retrieved an import file, for example.

Thanks in advance.
 
You can set InitDir at runtime:

CommonDialog1.InitDir = "c:\"
CommonDialog1.FileName = "*.mp3"
CommonDialog1.ShowOpen

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Thanks - but that is precisely what I am doing. It only seems to work on the first call to the dialog.

I have a browse button. The user clicks for the first time and, whoopee, it goes where I want (C:\fred\graphics). The user navigates elsewhere (F:\joe\awkward) and picks a file. User clicks the browse button again, I set InitDir again to 'C:\fred\graphics' but the dialog goes straight to 'F:\joe\awkward'.

Code:
  Dim ErNo As Long
  With FrmMenu.cdgApp
    .Filter = "Image files (*.gif;*.jpg)|*.gif;*.jpg"
    .DialogTitle = "Browse for pictures"
    .InitDir = GlbGraDir
    .CancelError = True
    .Flags = cdlOFNFileMustExist
    On Error Resume Next
    .ShowOpen
    ErNo = Err.Number
    If ErrTrap Then On Error GoTo LfnBrowseErr Else On Error GoTo 0
    If ErNo <> cdlCancel Then Fm.Table!DlzMapFile = .FileName
  End With
 
This is perplexing. Research elsewhere suggests that the InitDir property should behave as I want it to - i.e. each time the dialog is called it should start in the folder it specifies.

Can anyone confirm this?

Also any ideas of what the version of Comdlg32.ocx should be? Mine is 6.0.84.18. Could I be out of date?
 
It seems faintly bizarre, but if you set the FileName property it seems to do what you want:

.FileName = "*.*"


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
johnwm has hit the nail on the head. The issue is that, when a user selects a file first time around this po;ulates the .Filename property - and .Filename overrides .InitDir (.Filename holds both the path and the filename, and temporarily overwrites .InitDir)

So, you just nead to clear .FileName for .InitDir to work again...
 
Praise the Lord!!!! How on earth did you stumble upon that? In fact I have used

.FileName = ""

Surely someone has stumbled across this before - I couldn't find anything in this forum or elsewhere.

>faintly bizarre

I think I would have chosen a different adjective.

Thanks very, very much!
 
Strongm sneaked in while I was typing but thanks for explanation.
 
Thanks for the explanation strongm - I knew it worked from my original post, so I experimented to find the difference!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top