尝试备份数据库后端时出现错误 70 权限被拒绝
Error 70 Permission Denied when attempting to Backup Database Backend
我正在尝试自动备份位于网络驱动器上的拆分数据库的后端。不幸的是,我一直收到标题中显示的错误。
代码:
Function BackUpBE()
On Error GoTo Err_backup
Dim strNewBEname As String
Dim strOldBEname As String
Dim strDateStamp As String
strOldBEname = "P:\Access Datenbank\Durament_db_be\Durament_db_be.accdb"
'strOldBEname = "\192.XXX.XX.XXX\Daten\Access Datenbank\Durament_db_be\Durament_db_be.accdb"
strDateStamp = Format(Date, "d.m.yy")
strNewBEname = "P:\Access Datenbank\Durament_db_be\BackUp\" & "Backup_vom_" & strDateStamp & ".accdb"
'strNewBEname = "\192.XXX.XX.XXX\Daten\Access Datenbank\Durament_db_be\BackUp\" & "Backup_vom_" & strDateStamp & ".accdb"
'copy database
FileCopy strOldBEname, strNewBEname
MsgBox "The back-end database has been backed up!"
Exit_Backup:
Exit Function
Err_backup:
MsgBox Err.Number & Err.Description
Resume Exit_Backup
End Function
代码只是将当前后端复制到另一个文件夹中。起初我认为这是一个与所需密码有关的服务器相关问题。所以我映射了驱动器并使用了本地路径,但是,它仍然不起作用。我已经使用 f8 单步执行了代码,并且在退出函数时发生错误,这对我来说没有多大意义。感谢任何能让我在我的代码中找到错误部分的提示,在此先感谢。
正如@Andre 建议的那样,我设法在使用前端时使用 FileSystemObject 复制后端。
Function BackUpBE()
On Error GoTo Err_backup
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
Dim strNewBEname As String
Dim strOldBEname As String
Dim strDateStamp As String
strOldBEname = "P:\Access Datenbank\Durament_db_be\Durament_db_be.accdb"
'strOldBEname = "\192.XXX.XX.XXX\Daten\Access Datenbank\Durament_db_be\Durament_db_be.accdb"
strDateStamp = Format(Date, "d.m.yy")
strNewBEname = "P:\Access Datenbank\Durament_db_be\BackUp\" & "Backup_vom_" & strDateStamp & ".accdb"
'strNewBEname = "\192.XXX.XX.XXX\Daten\Access Datenbank\Durament_db_be\BackUp\" & "Backup_vom_" & strDateStamp & ".accdb"
'copy current BE to Folder
Call fso.CopyFile(strOldBEname, strNewBEname)
MsgBox "The back-end database has been backed up!"
Exit_Backup:
Exit Function
Err_backup:
MsgBox Err.Number & Err.Description
Resume Exit_Backup
End Function
我正在尝试自动备份位于网络驱动器上的拆分数据库的后端。不幸的是,我一直收到标题中显示的错误。
代码:
Function BackUpBE()
On Error GoTo Err_backup
Dim strNewBEname As String
Dim strOldBEname As String
Dim strDateStamp As String
strOldBEname = "P:\Access Datenbank\Durament_db_be\Durament_db_be.accdb"
'strOldBEname = "\192.XXX.XX.XXX\Daten\Access Datenbank\Durament_db_be\Durament_db_be.accdb"
strDateStamp = Format(Date, "d.m.yy")
strNewBEname = "P:\Access Datenbank\Durament_db_be\BackUp\" & "Backup_vom_" & strDateStamp & ".accdb"
'strNewBEname = "\192.XXX.XX.XXX\Daten\Access Datenbank\Durament_db_be\BackUp\" & "Backup_vom_" & strDateStamp & ".accdb"
'copy database
FileCopy strOldBEname, strNewBEname
MsgBox "The back-end database has been backed up!"
Exit_Backup:
Exit Function
Err_backup:
MsgBox Err.Number & Err.Description
Resume Exit_Backup
End Function
代码只是将当前后端复制到另一个文件夹中。起初我认为这是一个与所需密码有关的服务器相关问题。所以我映射了驱动器并使用了本地路径,但是,它仍然不起作用。我已经使用 f8 单步执行了代码,并且在退出函数时发生错误,这对我来说没有多大意义。感谢任何能让我在我的代码中找到错误部分的提示,在此先感谢。
正如@Andre 建议的那样,我设法在使用前端时使用 FileSystemObject 复制后端。
Function BackUpBE()
On Error GoTo Err_backup
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
Dim strNewBEname As String
Dim strOldBEname As String
Dim strDateStamp As String
strOldBEname = "P:\Access Datenbank\Durament_db_be\Durament_db_be.accdb"
'strOldBEname = "\192.XXX.XX.XXX\Daten\Access Datenbank\Durament_db_be\Durament_db_be.accdb"
strDateStamp = Format(Date, "d.m.yy")
strNewBEname = "P:\Access Datenbank\Durament_db_be\BackUp\" & "Backup_vom_" & strDateStamp & ".accdb"
'strNewBEname = "\192.XXX.XX.XXX\Daten\Access Datenbank\Durament_db_be\BackUp\" & "Backup_vom_" & strDateStamp & ".accdb"
'copy current BE to Folder
Call fso.CopyFile(strOldBEname, strNewBEname)
MsgBox "The back-end database has been backed up!"
Exit_Backup:
Exit Function
Err_backup:
MsgBox Err.Number & Err.Description
Resume Exit_Backup
End Function