Solved

VB 5.0 filecopy

Posted on 1998-10-05
8
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to mongodb 2 165
Passing a Text Box name to a Sub 6 104
Zip Folders Using Chilkat Routines 1 86
Modify Text File with Excel Macro 13 51
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 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