Backup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ive tried several different ways but had no luck

What is the best way to backup an access2003 database from a cmd button??
 
Here's what I do ...

Public Function CreateBackupFile() As Boolean
On Error GoTo Err_Handler

Dim strSBackupFolder As String
Dim strSSource As String
Dim strSTarget As String
Dim strSMsg As String
Dim frm As Form
Dim objFSO As FileSystemObject
Dim objFile As File
Dim strSTimeTag As String

DoCmd.Hourglass True
strSTimeTag = Format(Now(), "_yy-mm-dd_hh-nn")
Set objFSO = New FileSystemObject

strSBackupFolder = DLookup("[BackupFolder]", "[usysVersionServer]")

' backup current client file
strSSource = CurrentDb.Name
strSTarget = strSBackupFolder & gcstr_ClientFile & strSTimeTag & ".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

' backup primary data file
strSSource = Mid(CurrentDb.TableDefs("tblAgent").Connect, 11)
strSTarget = strSBackupFolder & gcstr_DataFile & strSTimeTag & ".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

Set objFSO = Nothing
DoCmd.Hourglass False

Exit_Here:
Exit Function
Err_Handler:
MsgBox Err.Description
Resume Exit_Here
End Function
 
This is helpful, but I need the reference for FileSystemObjects. Do you know
where in the library of references this is found?
Thank you,
Karl

Danny J. Lesandrini said:
Here's what I do ...

Public Function CreateBackupFile() As Boolean
On Error GoTo Err_Handler

Dim strSBackupFolder As String
Dim strSSource As String
Dim strSTarget As String
Dim strSMsg As String
Dim frm As Form
Dim objFSO As FileSystemObject
Dim objFile As File
Dim strSTimeTag As String

DoCmd.Hourglass True
strSTimeTag = Format(Now(), "_yy-mm-dd_hh-nn")
Set objFSO = New FileSystemObject

strSBackupFolder = DLookup("[BackupFolder]", "[usysVersionServer]")

' backup current client file
strSSource = CurrentDb.Name
strSTarget = strSBackupFolder & gcstr_ClientFile & strSTimeTag & ".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

' backup primary data file
strSSource = Mid(CurrentDb.TableDefs("tblAgent").Connect, 11)
strSTarget = strSBackupFolder & gcstr_DataFile & strSTimeTag & ".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

Set objFSO = Nothing
DoCmd.Hourglass False

Exit_Here:
Exit Function
Err_Handler:
MsgBox Err.Description
Resume Exit_Here
End Function



--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast/



StuJol said:
Ive tried several different ways but had no luck

What is the best way to backup an access2003 database from a cmd button??
 
The reference you need is 'Microsoft Scripting Runtime'.

--
Brendan Reynolds

Karl H said:
This is helpful, but I need the reference for FileSystemObjects. Do you
know
where in the library of references this is found?
Thank you,
Karl

Danny J. Lesandrini said:
Here's what I do ...

Public Function CreateBackupFile() As Boolean
On Error GoTo Err_Handler

Dim strSBackupFolder As String
Dim strSSource As String
Dim strSTarget As String
Dim strSMsg As String
Dim frm As Form
Dim objFSO As FileSystemObject
Dim objFile As File
Dim strSTimeTag As String

DoCmd.Hourglass True
strSTimeTag = Format(Now(), "_yy-mm-dd_hh-nn")
Set objFSO = New FileSystemObject

strSBackupFolder = DLookup("[BackupFolder]", "[usysVersionServer]")

' backup current client file
strSSource = CurrentDb.Name
strSTarget = strSBackupFolder & gcstr_ClientFile & strSTimeTag &
".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

' backup primary data file
strSSource = Mid(CurrentDb.TableDefs("tblAgent").Connect, 11)
strSTarget = strSBackupFolder & gcstr_DataFile & strSTimeTag & ".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

Set objFSO = Nothing
DoCmd.Hourglass False

Exit_Here:
Exit Function
Err_Handler:
MsgBox Err.Description
Resume Exit_Here
End Function



--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast/



StuJol said:
Ive tried several different ways but had no luck

What is the best way to backup an access2003 database from a cmd
button??
 
Actually, you don't need to set a reference.

You can use Late Binding instead. Change

Dim objFSO As FileSystemObject

to

Dim objFSO As Object

and

Set objFSO = New FileSystemObject

to

Set objFSO = CreateObject("Scripting.FileSystemObject")

Of course, I don't really understand why you would need FSO for this at all.
The VBA FileCopy statement should be sufficient.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Brendan Reynolds said:
The reference you need is 'Microsoft Scripting Runtime'.

--
Brendan Reynolds

Karl H said:
This is helpful, but I need the reference for FileSystemObjects. Do you
know
where in the library of references this is found?
Thank you,
Karl

Danny J. Lesandrini said:
Here's what I do ...

Public Function CreateBackupFile() As Boolean
On Error GoTo Err_Handler

Dim strSBackupFolder As String
Dim strSSource As String
Dim strSTarget As String
Dim strSMsg As String
Dim frm As Form
Dim objFSO As FileSystemObject
Dim objFile As File
Dim strSTimeTag As String

DoCmd.Hourglass True
strSTimeTag = Format(Now(), "_yy-mm-dd_hh-nn")
Set objFSO = New FileSystemObject

strSBackupFolder = DLookup("[BackupFolder]", "[usysVersionServer]")

' backup current client file
strSSource = CurrentDb.Name
strSTarget = strSBackupFolder & gcstr_ClientFile & strSTimeTag &
".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

' backup primary data file
strSSource = Mid(CurrentDb.TableDefs("tblAgent").Connect, 11)
strSTarget = strSBackupFolder & gcstr_DataFile & strSTimeTag & ".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

Set objFSO = Nothing
DoCmd.Hourglass False

Exit_Here:
Exit Function
Err_Handler:
MsgBox Err.Description
Resume Exit_Here
End Function



--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast/



Ive tried several different ways but had no luck

What is the best way to backup an access2003 database from a cmd
button??
 
When trying to compile this, "gcstr_ClientFile" comes up as an undefined
variable.

I also need help w/the DLookup line--I presume the backup folder needs to be
created in advance and this points to the folder. If I created a backup
folder and put:

strSBackupFolder = DLookup("[BackupFolder]", "[c:\Backup]")

would this work as a substitute?

Thank you,
Karl



Danny J. Lesandrini said:
Here's what I do ...

Public Function CreateBackupFile() As Boolean
On Error GoTo Err_Handler

Dim strSBackupFolder As String
Dim strSSource As String
Dim strSTarget As String
Dim strSMsg As String
Dim frm As Form
Dim objFSO As FileSystemObject
Dim objFile As File
Dim strSTimeTag As String

DoCmd.Hourglass True
strSTimeTag = Format(Now(), "_yy-mm-dd_hh-nn")
Set objFSO = New FileSystemObject

strSBackupFolder = DLookup("[BackupFolder]", "[usysVersionServer]")

' backup current client file
strSSource = CurrentDb.Name
strSTarget = strSBackupFolder & gcstr_ClientFile & strSTimeTag & ".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

' backup primary data file
strSSource = Mid(CurrentDb.TableDefs("tblAgent").Connect, 11)
strSTarget = strSBackupFolder & gcstr_DataFile & strSTimeTag & ".mdb"
Set objFile = objFSO.GetFile(strSSource)
objFile.Copy strSTarget
Set objFile = Nothing

Set objFSO = Nothing
DoCmd.Hourglass False

Exit_Here:
Exit Function
Err_Handler:
MsgBox Err.Description
Resume Exit_Here
End Function



--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast/



StuJol said:
Ive tried several different ways but had no luck

What is the best way to backup an access2003 database from a cmd button??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top