Solved

VB 5.0 filecopy

Posted on 1998-10-05
8
227 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:Bart van der Wee
  • 4
  • 3
8 Comments
 
LVL 7

Expert Comment

by:kamall
ID: 1438299
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
0
 
LVL 4

Author Comment

by:Bart van der Wee
ID: 1438300
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 ;-)
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1438301
Use shell and dos command:

copy c:\firstDb.mdb backupDb.mdb

I will post an example here soon.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 4

Author Comment

by:Bart van der Wee
ID: 1438302
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?
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1438303
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

0
 
LVL 3

Accepted Solution

by:
a111a111a111 earned 30 total points
ID: 1438304
Here is a code for you:




Private Sub Command1_Click()
Dim SourceFile, DestinationFile
Dim FilCpy
Dim txtDate
Dim MyTime

'On Error Resume Next
txtDate = Format(Now, "m-d-yyyy")

MyTime = Format(Time, "HHMMSS")
FilCpy = Shell("command.com /c copy c:\dbMain.mdb c:\dbBackup.mdb")
SourceFile = "C:\dbBackup.mdb"  ' Define source file name.
DestinationFile = "C:\" & MyTime & txtDate & ".mdb"    ' Define target file name.
'DestinationFile = "C:\11.mdb"
FileCopy SourceFile, DestinationFile    ' Copy source to target.


Unload Me

End Sub

Private Sub Timer1_Timer()
Command1_Click
End Sub

I can add the function of HOUR if needed.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1438305
 

Just try it then if it not works for you as I do now...
reject..
0
 
LVL 4

Author Comment

by:Bart van der Wee
ID: 1438306
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!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

825 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