Solved

Common Dialog Control : cannot eject removable drive until application exits

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now