谜爱阁生活网

如何复制当前打开的access数据库?

软件教程  2024-06-22 11:43:28  热度:36℃

‘复制当前打开的数据库
’********** Code Start *************
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type

Private Const FO_MOVE As Long = &H1
Private Const FO_COPY As Long = &H2
Private Const FO_DELETE As Long = &H3
Private Const FO_RENAME As Long = &H4

Private Const FOF_MULTIDESTFILES As Long = &H1
Private Const FOF_CONFIRMMOUSE As Long = &H2
Private Const FOF_SILENT As Long = &H4
Private Const FOF_RENAMEONCOLLISION As Long = &H8
Private Const FOF_NOCONFIRMATION As Long = &H10
Private Const FOF_WANTMAPPINGHANDLE As Long = &H20
Private Const FOF_CREATEPROGRESSDLG As Long = &H0
Private Const FOF_ALLOWUNDO As Long = &H40
Private Const FOF_FILESONLY As Long = &H80
Private Const FOF_SIMPLEPROGRESS As Long = &H100
Private Const FOF_NOCONFIRMMKDIR As Long = &H200

Private Declare Function apiSHFileOperation Lib "Shell32.dll" _
Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) _
As Long

Function fMakeBackup() As Boolean
Dim strMsg As String
Dim tshFileOp As SHFILEOPSTRUCT
Dim lngRet As Long
Dim strSaveFile As String
Dim lngFlags As Long
Const cERR_USER_CANCEL = vbObjectError + 1
Const cERR_DB_EXCLUSIVE = vbObjectError + 2
On Local Error GoTo fMakeBackup_Err

If fDBExclusive = True Then Err.Raise cERR_DB_EXCLUSIVE

strMsg = "Are you sure that you want to make a copy of the database?"
If MsgBox(strMsg, vbQuestion + vbYesNo, "Please confirm") = vbNo Then _
Err.Raise cERR_USER_CANCEL

lngFlags = FOF_SIMPLEPROGRESS Or _
FOF_FILESONLY Or _
FOF_RENAMEONCOLLISION
strSaveFile = CurrentDb.Name
With tshFileOp
.wFunc = FO_COPY
.hwnd = hWndAccessApp
.pFrom = CurrentDb.Name & vbNullChar
.pTo = strSaveFile & vbNullChar
.fFlags = lngFlags
End With
lngRet = apiSHFileOperation(tshFileOp)
fMakeBackup = (lngRet = 0)

fMakeBackup_End:
Exit Function
fMakeBackup_Err:
fMakeBackup = False
Select Case Err.Number
Case cERR_USER_CANCEL:
’do nothing
Case cERR_DB_EXCLUSIVE:
MsgBox "The current database " & vbCrLf & CurrentDb.Name & vbCrLf & _
vbCrLf & "is opened exclusively. Please reopen in shared mode" & _
" and try again.", vbCritical + vbOKOnly, "Database copy failed"
Case Else:
strMsg = "Error Information..." & vbCrLf & vbCrLf
strMsg = strMsg & "Function: fMakeBackup" & vbCrLf
strMsg = strMsg & "Description: " & Err.Description & vbCrLf
strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf
MsgBox strMsg, vbInformation, "fMakeBackup"
End Select
Resume fMakeBackup_End
End Function

Private Function fCurrentDBDir() As String
’code courtesy of
’Terry Kreft
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
fCurrentDBDir = left(strDBPath, InStr(strDBPath, strDBFile) - 1)
End Function

Function fDBExclusive() As Integer
Dim db As Database
Dim hFile As Integer
hFile = FreeFile
Set db = CurrentDb
On Error Resume Next
Open db.Name For Binary Access Read Write Shared As hFile
Select Case Err
Case 0
fDBExclusive = False
Case 70
fDBExclusive = True
Case Else
fDBExclusive = Err
End Select
Close hFile
On Error GoTo 0
End Function
’************* Code End ***************

 

以上就是如何复制当前打开的access数据库?的全部内容,望能这篇如何复制当前打开的access数据库?可以帮助您解决问题,能够解决大家的实际问题是谜爱阁生活网一直努力的方向和目标。

最近更新

  • 酷狗音乐中使用蝰蛇音效制作工具的具体操作方法

    酷狗音乐中使用蝰蛇音效制作工具的具体操作方法

    2024-11-111192阅读

  • win7电脑中出现声音图标不见了的具体解决方法

    win7电脑中出现声音图标不见了的具体解决方法

    2024-11-11833阅读

  • 车到哪app的详细软件介绍

    车到哪app的详细软件介绍

    2024-11-11929阅读

  • 小米9se中查看序列号的具体操作方法

    小米9se中查看序列号的具体操作方法

    2024-11-11907阅读

  • 迅雷中使用FTP探测器的详细操作方法

    迅雷中使用FTP探测器的详细操作方法

    2024-11-11919阅读

  • ppt制作出小荷才露尖尖角动画场景的具体操作步骤

    ppt制作出小荷才露尖尖角动画场景的具体操作步骤

    2024-11-11765阅读

  • 小米9se中清除内存的具体操作步骤

    小米9se中清除内存的具体操作步骤

    2024-11-11721阅读

  • 千牛中取消消息提醒的具体操作流程

    千牛中取消消息提醒的具体操作流程

    2024-11-11741阅读

  • 抖音app中两个人使用特效具体步骤介绍

    抖音app中两个人使用特效具体步骤介绍

    2024-11-11731阅读

  • 2018Mac mini值得购买吗?Mac mini配置参数及售价详解

    2018Mac mini值得购买吗?Mac mini配置参数及售价详解

    2024-11-11755阅读