Link to home
Start Free TrialLog in
Avatar of Bart van der Wee
Bart van der WeeFlag for New Zealand

asked on

VB 5.0 filecopy

I need to copy an access database file (.mdb) at regular intervals. I can do it manually using mouse drag and drop. However I want to automate this but the filecopy() command in VB5.0 won't work while someone is in the DB. How can I get around this? Is there another procedure that I can use?
Avatar of Dr. Kamal Mehdi
Dr. Kamal Mehdi
Flag of Greece image

Unfortunately, you can not copy a file while it is currently open.
However, you can do the following:
Insert a timer control or whatever you want for setting your interval for copying the database. In your code where you have the copy procedure segment, put:

On Error Resume Next

This will prevent an error from being generated when the DB is open. When your code executes successfully in copying the database (when it is closed) you can have a variable set so you can determine when your database was copied the last time.

Hope that helps.
Regards
Avatar of Bart van der Wee

ASKER

How come it works when I use the mouse method?? ie Right click on the mdb file (while there is a ldb file open) and copy the mdb file elsewhere?? If I don't get any joy just repost your answer and you'll get the points.
Thankx ;-)
Avatar of a111a111a111
a111a111a111

Use shell and dos command:

copy c:\firstDb.mdb backupDb.mdb

I will post an example here soon.
Maybe I need to clarify what I need: I need to backup an access database every hour, I also need to keep each backup. What I need is a backup that copies the MDB file (which can have people in it at anytime) and sets the file name to the current date and time of the copy. I have done this with VB5.0 but it does not work if someone is in the database (eg a LDB file is present) I think that this is just a limitation of the filecopy() function. Is there another function available? If I can use the Copy and Paste within a window is there no way of implementing this within a VB5 prog?
Here is the code for you:



Private Sub Command1_Click()
'On Error Resume Next
Dim FilCpy

FilCpy = Shell("command.com /c copy c:\dbMain.mdb c:\dbBackup.mdb")

Unload Me

End Sub

ASKER CERTIFIED SOLUTION
Avatar of a111a111a111
a111a111a111

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
 

Just try it then if it not works for you as I do now...
reject..
Thank you. It works well once I put in a delay so that the dos copy could finish ;-) it was a 10MB database and I am copying to network drives!