Solved

VB 5.0 filecopy

Posted on 1998-10-05
8
225 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

705 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

14 Experts available now in Live!

Get 1:1 Help Now