?
Solved

Common Dialog Box won't observe INITDIR value

Posted on 2009-07-02
5
Medium Priority
?
929 Views
Last Modified: 2013-11-25
I have a form with a lot of command buttons all launching the COMMON DIALOG BOX ( names CD1 in my app)
Under each command button there is a different CD1.INITDIR value (for different folders on the drive)
The problem is that the COMMON DIALOG control is not changing to each individual directory. Whatever one I choose first, is the one that each COMMAND BUTTON opens up, regardless of what the CD1.INITDIR value is set to. I even DEBUGd it and watched the value of INITDIR and it IS CHANGING to the right folder, but the DIALOG box keeps opening up to the same folder as the first one I pick.
Help...

On Error GoTo ExitMe
seld = 2
Command2.Value = 0
DoEvents
 
CD1.InitDir = Text37.Text
CD1.Filter = "MP3 Audio File (*.mp3)|*.mp3"
CD1.DefaultExt = "mp3"
CD1.DialogTitle = "Select Audio File"
CD1.CancelError = False
CD1.ShowOpen
 
 
Text2.Text = CD1.FileName
DoEvents
CD1.FileName = ""
 
Exit Sub
ExitMe:
MsgBox "Error " & Err.Number & ": " & Err.Description & vbCrLf & "in Save" & vbCrLf & "The error occured at line: " & Erl, vbAbortRetryIgnore + vbCritical, "Error"

Open in new window

0
Comment
Question by:rbend
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:jgbreeden
ID: 24769055
where is CD1 declared? If it is outside of this sub, maybe if you move it into this sub it will reload properly since it will go out of scope at the end of the sub.
0
 

Author Comment

by:rbend
ID: 24769174
The same code as above is in each COMMAND button, with only 2 things changed.. one being the initial directory of CD1
So I would say it is declared in every button
0
 

Accepted Solution

by:
rbend earned 0 total points
ID: 24771582
Found my own solution:
This works everytime:

--------------------------------------------------
Function fBrowseForFile(pathto)
' This function opens a common file browsing dialog box
' pointed at the local C:\ drive.  When a file is selected
' this function will return the path and filename in a string.
' If cancel is clicked or the browse window is closed without
' a file being selected, the function returns an empty string.
sBrowsePath = pathto
sBrowseFilter = "All Files|*.mp3"
Set oBrowseDialog = CreateObject("UserAccounts.CommonDialog")
oBrowseDialog.Filter = sBrowseFilter
oBrowseDialog.InitialDir = sBrowsePath
oBrowseDialog.Flags = &H80000 + &H4 + &H8
oBrowseDialog.ShowOpen
fBrowseForFile = oBrowseDialog.FileName
End Function
-----------------------------------------------

Open in new window

0
 
LVL 5

Expert Comment

by:jgbreeden
ID: 24772984
That should do it, the main point being that you are creating it inside the function.  There is probably a
Dim CD1 statement at the form level, moving that inside the function would have the same effect.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question