Solved

Common Dialog Control : cannot eject removable drive until application exits

Posted on 2007-12-06
1
448 Views
Last Modified: 2013-12-25
I am using the Common Dialog Control in VB6 with the purpose to save a copy of a file.
However, if I select the destination to be a removable drive (e.g. USB flash drive),
if I then try to "unplug/eject the hardware" (even though the form used to perform the save is closed)
the messagebox appears "The device 'Generic volume' cannot be stopped right now. Try stopping the device later."
I have isolated the problem to be the Common Dialog Control itself (after selecting the file, I now do nothing but exit the form.) It is statically placed on the form.
I also attempted to instead dynamically add the Common Dialog Control to the form, use it, remove it from the form and set the object to nothing but had the same result.
Any idea how to get beyond this problem?
Private Sub cmdSave_Click()
Dim sFilePathAndName as String
 
    On Error Goto cmdSave_Exit
 
    With dlgFolder
        .CancelError = True
        .DefaultExt = ".txt"
        .Filter = "Text File (*.txt)|*.txt"
        .DialogTitle = "Save As"
        .flags = cdlOFNExplorer + cdlOFNNoReadOnlyReturn + cdlOFNOverwritePrompt _
                + cdlOFNPathMustExist
        .ShowSave
 
        sFilePathAndName = .FileName
    End With
 
    ' trivial case to show problem
    ' just exit the form and leave the application running,
    ' then try to eject the removable media
 
    Debug.Print sFilePathAndName
 
cmdSave_Exit:
    Unload Me
End Sub

Open in new window

0
Comment
Question by:James_Clements
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 20423098
The default behaviour of that control is to set the directory in which you pick the afile as the current directory, which causes that effect - either call 'SetCurrentDirectory()' yourself or add 'cdlOFNNoChangeDir' (OFN_NOCHANGEDIR, see also http://msdn2.microsoft.com/en-us/library/ms646839.aspx - "OPENFILENAME") to your flags.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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