Solved

Common Dialog Control : cannot eject removable drive until application exits

Posted on 2007-12-06
1
449 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Zip Folders Using Chilkat Routines 1 58
Formula problem with Excel attachment 6 38
Problem to line 23 53
VBA: loop recent folder and copy txt file. 8 33
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

840 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