gerard1979
MIS
I want to back up my backend database by code:
I wrote (with help of tekTips) the code below.
But the function failed on the line
fso.CopyFile strSource, strDest, True
Can the cause be my PROTECTED backend
The error is Number 52,
Thnx in advance
Public Sub BackUp()
'This function backs up to the c: drive, you can back up to any location, just change the strDest Value
On Error GoTo Err_Backup
Dim db As Database
Dim strSource As String, strDest As String, strError As String
Dim strDate As String, strDateX As String
Dim fso As FileSystemObject
If Bevestigen("Wilt u een back-up van de data maken?" Then
' Un-comment the following 3 lines for a new backup for every day
strDate = Format(Date, "mm/dd/yy"
strDateX = Left(strDate, 2) & Mid(strDate, 4, 2) & Right(strDate, 2)
strDest = "C:\" & strDateX
Set db = CurrentDb()
DoCmd.Hourglass True
'Put any table name in here that exists in your back-end
strSource = db.TableDefs("CONTACTPERSOON".Connect
strSource = Mid(strSource, 11, Len(strSource) - 10)
' If you are using a new back-up every day, un-comment this line and replace the database name, and comment
'out the next line down
strDest = strDest & "_BackUpAcquisitie_be.mdb"
Set fso = New FileSystemObject
fso.CopyFile strSource, strDest, True
db.Close
Set fso = Nothing
DoCmd.Hourglass False
BerichtWeergeven ("Backup Compleet....."
Dim emailTo As String, strOnderwerp As String, strBericht As String
emailTo = HaalEmail("Gkr"
strOnderwerp = "backup van data gemaakt"
strBericht = ""
strBericht = strBericht & "Datum: " & Date & vbNewLine
strBericht = strBericht & "Een kopie van de data is weggeschreven naar " & strDest & vbNewLine
strBericht = strBericht & "Er hebben zich geen fouten voorgedaan......."
fctnOutlook EmailCRM, emailTo, , , strOnderwerp, strBericht, , , False
End If
Exit_Backup:
Exit Sub
Err_Backup:
Select Case Err.Number
Case 61
strError = "Schijf is vol" & vbNewLine & "Kan geen backup maken"
MsgBox strError, vbCritical, " Disk Full"
Kill strDest
Case 71
strError = "Geen schijf in de Zip-drive" & vbNewLine & "Voer schijf in, aub"
MsgBox strError, vbCritical, " No Disk"
Case Else
Err.Raise Err.Number, Err.Description
End Select
DoCmd.Hourglass False
Resume Exit_Backup
End Sub
I wrote (with help of tekTips) the code below.
But the function failed on the line
fso.CopyFile strSource, strDest, True
Can the cause be my PROTECTED backend
The error is Number 52,
Thnx in advance
Public Sub BackUp()
'This function backs up to the c: drive, you can back up to any location, just change the strDest Value
On Error GoTo Err_Backup
Dim db As Database
Dim strSource As String, strDest As String, strError As String
Dim strDate As String, strDateX As String
Dim fso As FileSystemObject
If Bevestigen("Wilt u een back-up van de data maken?" Then
' Un-comment the following 3 lines for a new backup for every day
strDate = Format(Date, "mm/dd/yy"
strDateX = Left(strDate, 2) & Mid(strDate, 4, 2) & Right(strDate, 2)
strDest = "C:\" & strDateX
Set db = CurrentDb()
DoCmd.Hourglass True
'Put any table name in here that exists in your back-end
strSource = db.TableDefs("CONTACTPERSOON".Connect
strSource = Mid(strSource, 11, Len(strSource) - 10)
' If you are using a new back-up every day, un-comment this line and replace the database name, and comment
'out the next line down
strDest = strDest & "_BackUpAcquisitie_be.mdb"
Set fso = New FileSystemObject
fso.CopyFile strSource, strDest, True
db.Close
Set fso = Nothing
DoCmd.Hourglass False
BerichtWeergeven ("Backup Compleet....."
Dim emailTo As String, strOnderwerp As String, strBericht As String
emailTo = HaalEmail("Gkr"
strOnderwerp = "backup van data gemaakt"
strBericht = ""
strBericht = strBericht & "Datum: " & Date & vbNewLine
strBericht = strBericht & "Een kopie van de data is weggeschreven naar " & strDest & vbNewLine
strBericht = strBericht & "Er hebben zich geen fouten voorgedaan......."
fctnOutlook EmailCRM, emailTo, , , strOnderwerp, strBericht, , , False
End If
Exit_Backup:
Exit Sub
Err_Backup:
Select Case Err.Number
Case 61
strError = "Schijf is vol" & vbNewLine & "Kan geen backup maken"
MsgBox strError, vbCritical, " Disk Full"
Kill strDest
Case 71
strError = "Geen schijf in de Zip-drive" & vbNewLine & "Voer schijf in, aub"
MsgBox strError, vbCritical, " No Disk"
Case Else
Err.Raise Err.Number, Err.Description
End Select
DoCmd.Hourglass False
Resume Exit_Backup
End Sub