Bart van der Wee
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?
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 ;-)
Thankx ;-)
Use shell and dos command:
copy c:\firstDb.mdb backupDb.mdb
I will post an example here soon.
copy c:\firstDb.mdb backupDb.mdb
I will post an example here soon.
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just try it then if it not works for you as I do now...
reject..
ASKER
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!
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