Disconnect from FlashDisk

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created a routine to copy a BackEnd to a FlashDisk so that a colleague
can take it away and use it with a FrontEnd already on his desktop.
Everything works OK except that when I try to 'Stop' the FlashDisk (by
clicking the icon in the bottom right of the screen) before removing it, as
W2k requires you to do, I get an error saying the device cant be stopped at
this time. I have found that if I open a File Open dialog and navigate to a
different drive, I can then stop the device with no problem, so I guess that
I am getting the error because the FlashDisk is still connected to the
database in some way. Is there any way to disconnect the FlashDisk or change
the connected drive programatically?
Thanks
N.B. I am not copying the BackEnd wholesale, only certain data pertaining to
my colleague. Thats why I'm doing this with a program rather than just
copying it in Explororer
 
Hi,

how do you copy the mdb to the usb drive? If you do it with
FileSystemObjects, you have to destroy the instance of the file after copying
in vba, e.g.

Set OFile = Nothing
Set oFSO = Nothing

After doing this, no handle to this file should be open and you can
disconnect the usb drive.
 
Hi thanks for your reply.

No, I'm using

'Copy source to target.
FileCopy SourceFile, DestinationFile

I've tried your suggestion but it doesn't have any effect.
 
Hi,

could you please paste the complete code of the function, which copies the
database. It is easier to fix your problem when I have a look at the code. ;-)
 
Hi Oliver, here it is:

'copy the file to the FlashDisk
'Define source file name.
SourceFile = "C:/SYM/" & strTeacher & "_PU.mde"

'Define target file name.
DestinationFile = FileName ' (variable FileName contains path to usb
drive)

'Copy source to target.
FileCopy SourceFile, DestinationFile

Kill SourceFile 'delete the file from the HD

Thanks
 
Hi,

only for my understanding, you somehow extract parts of the master database
to a second database, close all connections to this new database (filecopy
won't work correctly if the copied file is open) and then copy it to the usb
drive? Correct!?

Sorry, but that should work fine like your pasted code, is it possible that
the ms explorer point to the drive you want to disconnect or that another
application has an open file handle on the usb drive?

If all these assumptions are false, please try if it happens, when you copy
the file using the FileSystemObject.

Example:

Function fctCopyFile(strFilename As String, strNewFilename As String)
''On Error Resume Next
' Declaration
Dim objFSO As Scripting.FileSystemObject
Dim objFile As Scripting.File

Set objFSO = New Scripting.FileSystemObject
Set objFile = objFSO.GetFile(strFilename)

objFile.Copy strNewFilename

Set objFile = Nothing
Set objFSO = Nothing

End Function

Hope that will help
 
Hi Oliver

I think MS Explorer is pointing to the USB drive because I use the Windows
Common Dialog Open File box earlier in the program to get the path to the
drive (which is contained in the variable FileName). I have tried opening
the Open File box again and selecting another drive. This cures the problem,
but I would like to do it in the program.
 
I suspect your current directory is being reset by the Open File box.

I always use the API approach shown in
http://www.mvps.org/access/api/api0001.htm at "The Access Web". Using that
code, you can include the ahtOFN_NOCHANGEDIR flag when you're calling the
dialog, and your current directory will not be changed. I would assume the
same can be done with the OCX, if that's what you're using.

The other alternative would be to issue a ChDir command after you're done.
 
Thanks for your reply Douglas

I have tried ChDir with no success. The code I use to open the file dialog
is from one of the various groups there are around, I've been using it in a
number of programs for some time and have not had any problems before. I just
need to find a way to make it point to another directory without actually
opening the dialog a second time, I suppose I'm asking too much?
 
Actually, now that I think about it some more, it's ChDrive you'll need to
use: while ChDir will change the default directory, it doesn't change the
default drive.

Did you try to see whether you can use OFN_NOCHANGEDIR flag (which is equal
to &H8) with however you're invoking the dialog? Randy Birch has an
excellent overview of how the API works at
http://vbnet.mvps.org/code/comdlg/filedlgsoverview.htm
 
Thanks Douglas, ChDrive has done the trick!

Douglas J Steele said:
Actually, now that I think about it some more, it's ChDrive you'll need to
use: while ChDir will change the default directory, it doesn't change the
default drive.

Did you try to see whether you can use OFN_NOCHANGEDIR flag (which is equal
to &H8) with however you're invoking the dialog? Randy Birch has an
excellent overview of how the API works at
http://vbnet.mvps.org/code/comdlg/filedlgsoverview.htm
 
Further to my previous reply, and probably oustaying my welcome, but I
suppose there's no way of Stopping the USB drive programatically?
 
Hi Oliver, thanks for the suggestion.

I have downloaded and extracted the file, but I have not got a clue as to
how to implement this in VB. Could you point me in the right direction
please?

Wes.
 
Try:

Dim strShell As String

strShell = "<full path to deveject.exe> -EjectName:""USB Mass Storage
Device"""
Shell strShell, vbHide

Replace <full path to deveject.exe> as appropriate.
 
Thanks for your reply Douglas

I have tried the code you suggested, but although it seems to run with no
problems, it still doesn't stop the device, which is a USB2 PenDrive

My code is as follows:

Dim strShell As String

strShell = "C:\SYM\deveject.exe -EjectName:""USB Mass Storage Device"""

Shell strShell, vbHide

Any help would be most welcome
 
You may have to play with what you pass after EjectName. What I typed there
worked for me. See what happens if you use USB2 PenDrive instead.
 
Back
Top