Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB 5.0 filecopy

Posted on 1998-10-05
8
Medium Priority
?
232 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 120 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

715 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