Solved

Common Dialog Control : cannot eject removable drive until application exits

Posted on 2007-12-06
1
451 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
[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
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…

710 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