Solved

VB 5.0 filecopy

Posted on 1998-10-05
8
226 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
 
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
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.

 
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

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now