如何使用 VBA 从同一数据库文件中重新启动 Microsoft Access 2007..??
我正在开发一个数据库,最终将与运行时一起打包和分发。为了进行开发,我更改了各种 UI 设置,并在 *.accdb 和 *.accdr 之间来回重命名文件。但我想使用完全编程的方法,然后将其分配给按钮或击键。
但是任何尝试过的人都可以告诉您,人们无法轻松地使用 VBA 从同一数据库中重新启动 Access。我在这里尝试了代码:MS Access: how to compact current database in VBA ,但我收到错误消息“您无法通过运行宏或 Visual Basic 代码来压缩打开的数据库。”
我有各种不成熟的想法如何“反弹”重新启动 VBS 脚本、CMD 文件或另一个 Accdb 文件,但我想问还有谁可能成功地做到了这一点..??
其他人通过哪些方式取得了成功......?
最佳答案
我按照以下步骤复制新版本的前端,然后打开。不幸的是,当 IT 加强安全性且无法再以编程方式复制文件时,不得不放弃。不要问我为什么它有效,它已经找到了代码。以前,我让 VBA 调用 VBScript,它会执行复制并重新打开。
Private Sub Form_Load()
'Check for updates to the program on start up - if values don't match then there is a later version
If Me.tbxVersion <> Me.lblVersion.Caption Then
'because administrator opens the master development copy, only run this for non-administrator users
If DLookup("Permissions", "Users", "UserNetworkID='" & Environ("UserName") & "'") <> "admin" Then
'copy Access file
CreateObject("Scripting.FileSystemObject").CopyFile _
gstrBasePath & "Program\Install\MaterialsDatabase.accdb", "c:\", True
'allow enough time for file to completely copy before opening
Dim Start As Double
Start = Timer
While Timer < Start + 3
DoEvents
Wend
'load new version - SysCmd function gets the Access executable file path
'Shell function requires literal quote marks in the target filename string argument, apostrophe delimiters fail, hence the quadrupled quote marks
Shell SysCmd(acSysCmdAccessDir) & "MSAccess.exe " & """" & CurrentProject.FullName & """", vbNormalFocus
'close current file
DoCmd.Quit
End If Else
'tbxVersion available only to administrator to update version number in Updates table
Me.tbxVersion.Visible = False
Call UserLogin End If
End Sub
关于ms-access - 如何从 Microsoft Access 中使用 VBA 重新启动 Microsoft Access?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45537980/