Access 2007从VBA SysCmd 603制作ACCDE

问题描述 投票:1回答:2

我正在尝试自动执行我通常运行的任务来压缩我的数据库,保存备份,并更新我正在使用的自动更新系统的版本号。我坚持尝试用vba脚本制作一个accde文件。

我发现的与该主题有关的一切似乎都指向使用这样的东西。

function MakeACCDE(InPath As String, OutPath As String)

Dim app As New Access.Application

app.AutomationSecurity = msoAutomationSecurityLow

app.SysCmd 603, InPath, OutPath

End Function

各种论坛上的一些用户声称这段代码适用于他们,但我没有运气。我的数据库运行代码没有错误,但没有实际发生。

是否有一个特定的语法我没有使用或者可能是文件路径的格式?

vba access-vba ms-access-2007
2个回答
1
投票

我在http://www.experts-exchange.com/questions/28429044/How-do-I-create-an-Access-2010-accde-from-VBA.html找到了以下代码

我插入到Access 2010 accdb中,运行它,然后创建了一个accde

**更新:看到你想从不同的数据库运行,我测试了它...只需将'tmpDB_Full_Name = CurrentProject.FullName'行改为你的源数据库

Option Compare Database
Option Explicit

Function Create_MDE()
 Dim tmpDB_Full_Name As String
    Dim tmpDB_Name As String
    Dim tmpDB_Backup_Full_Name As String
    Dim tmpCopy_File As Variant
    Dim tmpDirectory As String

    'Call SetStartupOptions("AllowBypassKey", dbBoolean, False)               '---This runs a procedure to deactivate the Shift & F11 key

    'tmpDB_Full_Name = CurrentProject.FullName
    tmpDB_Full_Name = "C:\data\access\MyDb.accdb"
    tmpDirectory = CurrentProject.Path
    tmpDB_Name = CurrentProject.Name

    tmpDB_Backup_Full_Name = tmpDirectory & "\" & left(tmpDB_Name, Len(tmpDB_Name) - 6) & "-Backup.accdb"

    'this removes a file created on the same day
    If Dir(tmpDB_Backup_Full_Name) <> "" Then

        Kill tmpDB_Backup_Full_Name

    End If

    'this creates a backup into destination tmpDirectory
    If Dir(tmpDB_Backup_Full_Name) = "" Then

        Set tmpCopy_File = CreateObject("Scripting.FileSystemObject")
        tmpCopy_File.CopyFile tmpDB_Full_Name, tmpDB_Backup_Full_Name, True

    End If

    Dim app As New Access.Application

    app.AutomationSecurity = msoAutomationSecurityLow

    app.SysCmd 603, tmpDB_Backup_Full_Name, tmpDirectory & "\" & left(tmpDB_Name, Len(tmpDB_Name) - 9) & ".accde"

    'Call SetStartupOptions("AllowBypassKey", dbBoolean, True)                 '---This runs a procedure to activate the Shift & F11

    MsgBox ("Compile Complete!")

End Function

0
投票

我已使用ACCDE和ACCDR作为目标文件扩展名在Access 2016中测试了以下代码:

        Dim otherAccess As Access.Application
        Set otherAccess = New Access.Application
        otherAccess.AutomationSecurity = 1 'msoAutomationSecurityLow
        otherAccess.SysCmd 603, InPath, OutPath
        otherAccess.Quit acQuitSaveNone
        Set otherAccess = Nothing
© www.soinside.com 2019 - 2024. All rights reserved.