MaggieKCSR
Technical User
We have a data backup function attached to a button on our frontend. The back up function copies the open backend file to the root on the C: drive. This worked for years in XP. In Win7 this either gives an error "The expression On Click you entered as the event property setting produced the following error: Permission Denied". This error occurs or Access just locks up. Here is the code...I hope someone has an answer.
"
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 MsgBox("Would you like to back up your data to drive C:?", vbQuestion + vbYesNo, " Continue?") = vbYes 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 = "a:\" & strDateX
Set db = CurrentDb()
DoCmd.Hourglass True
'Put any table name in here that exists in your back-end
strSource = db.TableDefs("QME/AME Information").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 & "_db1_be.accdb"
' Replace with your database Back-end name and different drive letter or UNC Path if desired
strDest = "C:\db1_be.accdb"
Set fso = New FileSystemObject
fso.copyfile strSource, strDest, True
db.Close
Set fso = Nothing
DoCmd.Hourglass False
MsgBox ("Backup Complete, Please Open Windows Explorer and Verify that the File db1_be.accdb was copied to your Back Up Destination")
End If
Exit_Backup:
Exit Sub
Err_Backup:
Select Case Err.number
Case 61
strError = "Disk is full" & vbNewLine & "cannot export accdb"
MsgBox strError, vbCritical, " Disk Full"
Kill strDest
Case 71
strError = "No disk in drive" & vbNewLine & "please insert disk"
MsgBox strError, vbCritical, " No Disk"
Case Else
Err.Raise Err.number, Err.Description
End Select
DoCmd.Hourglass False
Resume Exit_Backup
End Sub
"
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 MsgBox("Would you like to back up your data to drive C:?", vbQuestion + vbYesNo, " Continue?") = vbYes 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 = "a:\" & strDateX
Set db = CurrentDb()
DoCmd.Hourglass True
'Put any table name in here that exists in your back-end
strSource = db.TableDefs("QME/AME Information").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 & "_db1_be.accdb"
' Replace with your database Back-end name and different drive letter or UNC Path if desired
strDest = "C:\db1_be.accdb"
Set fso = New FileSystemObject
fso.copyfile strSource, strDest, True
db.Close
Set fso = Nothing
DoCmd.Hourglass False
MsgBox ("Backup Complete, Please Open Windows Explorer and Verify that the File db1_be.accdb was copied to your Back Up Destination")
End If
Exit_Backup:
Exit Sub
Err_Backup:
Select Case Err.number
Case 61
strError = "Disk is full" & vbNewLine & "cannot export accdb"
MsgBox strError, vbCritical, " Disk Full"
Kill strDest
Case 71
strError = "No disk in drive" & vbNewLine & "please insert disk"
MsgBox strError, vbCritical, " No Disk"
Case Else
Err.Raise Err.number, Err.Description
End Select
DoCmd.Hourglass False
Resume Exit_Backup
End Sub