Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a backup file with a command button 2

Status
Not open for further replies.

gal4y

Technical User
Dec 24, 2001
72
US
I would like to create a backup file of the database while the database is open with a command button.

Is there an option to also backup the file at a specific time increment.

Thanks for any help

 
Well - here is an approach I used in the past.
1. Backup of open database - I created a copy of the database and coded my own psuedo replication routine that would "Transfer" the data to the replica database.
2. For backing up - you can create a seperate database file that has an autoexec macro. The macro can call a routine where you Copy the file & Compact it to another directory.
htwh Steve Medvid
"IT Consultant & Web Master"
 
You can Copy the File with the Same Name or Rename it with this function.

Source:
Function CopyFile(SourceName As String, DestName As String) As Integer
'
' Copies a single file SourceName to DestName
'
' Calling convention:
' X = CopyFile("C:\This.Exe", "C:\That.Exe")
' X = CopyFile("C:\This.Exe", "C:\Temp\This.Exe")
'
Const BufSize = 8192
Dim Buffer As String * BufSize, TempBuf As String
Dim SourceF As Integer, DestF As Integer, i As Long
On Error GoTo CFError
SourceF = FreeFile
Open SourceName For Binary As #SourceF
DestF = FreeFile
Open DestName For Binary As #DestF
For i = 1 To LOF(SourceF) \ BufSize
Get #SourceF, , Buffer
Put #DestF, , Buffer
Next i
i = LOF(SourceF) Mod BufSize
If i > 0 Then
Get #SourceF, , Buffer
TempBuf = left$(Buffer, i)
Put #DestF, , TempBuf
End If
Close #SourceF
Close #DestF
CopyFile = True

CFExit:
Exit Function

CFError:
Close
MsgBox "Error " & Err.Number & " copying files" & Chr$(13) & Chr$(10) & Error
CopyFile = False
Resume CFExit
End Function

Best Regards

---
JoaoTL
mail@jtl.co.pt
My MS Access Site:
 
Where do I put the code?
I have tried to put it into a module and then run it but it didn't work.

How do I run it from a command button?

Thanks
 
Hi

This is a Function...ok!!

So you have to put this line of code on the ButtonClick()

CopyFile("C:\YourDB.mdb", "C:\DBCopy.mdb")

BUT ATTENTION

You have to change the Path of the source file to Your DB Path in (C:\YourPath\YourDB.mdb) and then copy to were do you want (C:\YourPath\DBCopy.mdb)
Best Regards

---
JoaoTL
mail@jtl.co.pt
My MS Access Site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top