Solved

Common Dialog Control : cannot eject removable drive until application exits

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

867 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

18 Experts available now in Live!

Get 1:1 Help Now