【问题标题】:Run app.SaveAsText remotely in a secured Ms-Access Database在安全的 Ms-Access 数据库中远程运行 app.SaveAsText
【发布时间】:2017-07-20 07:34:30
【问题描述】:

我有一个 MS-Access 数据库,专门用于管理我的其他 MS-Access 数据库:)

我们称之为:AppManager

我在其中存储有关我开发的其他数据库的信息。

-它们都有不同的工作组文件,用于实现每个用户/组的安全权限-

.MDB/.MDW 的位置与(管理员的)用户名和密码一起存储在我的 AppManager 中

注意事项:

  • AppManager 是为了我自己的利益 - 因为我是那些 Dbs 的管理员/开发者-

  • .mdb 是因为在我们公司,我们仍在使用 MS-Access 2k - 具体来说是 2003-

  • .mdw 是安全工作组文件(没有它,任何安全数据库都无法打开)

现在我在 AppManager 中加入了各种功能: 例如查看组/用户信息、重置密码、其他自定义功能...等

我正在尝试向 AppManager 添加新功能 这将使我能够远程导出任何这些 Db 中的所有对象 - 从 AppManager 内部 -

代码如下:

    Function ConnectSecuredDB 
    ( MDBPath As String, MDWPath As String, UserName As String, Password As String) As Boolean

        Dim wsp As Workspace, db As Database, objEngine As DBEngine

        Set objEngine = New PrivDBEngine

        objEngine.SystemDB = MDWPath
        Set wsp = objEngine.CreateWorkspace("New", UserName, Password, dbUseJet)

        Set db = wsp.OpenDatabase(MDBPath)

        'I Do some stuff here...

        db.Close
        wsp.Close

        Set db = Nothing
        Set wsp = Nothing
    End Function

我需要将上面的代码与具有 Docmd、SaveAsText 方法的 Application 对象结合起来

就像这段代码取自MSDN - 但它不处理secured-mdw 数据库的问题-:

    Dim appAccess As Access.Application 

        Sub DisplayForm() 

        Dim strDB as String 

        ' Initialize string to database path. 
        Const strConPathToSamples = "C:\Program " _ 
    & "Files\Microsoft Office\Office11\Samples\" 

        strDB = strConPathToSamples & "Northwind.mdb" 

        ' Create new instance of Microsoft Access. 
        Set appAccess = _ 
        CreateObject("Access.Application") 

        ' Open database in Microsoft Access window. 
        appAccess.OpenCurrentDatabase strDB 

        ' Open Orders form. 
        appAccess.DoCmd.OpenForm "Orders" 
        End Sub

在我的情况下,我必须将最后一行替换为:

        With db.Containers("Modules")
          For Each doc In .Documents
            appAccess.SaveAsText acModule, doc.Name, "C:\temp\" & doc.Name & ".mod"
          Next doc
        End With
        'and repeat it with other objects reports, macros, ...

我的 ConnectSecuredDB 函数不包含 Access.Application 对象

关于如何实现这一点的任何想法?

我确实希望有一个解决方法。

谢谢

【问题讨论】:

    标签: vba ms-access-2003 working-remotely mdw


    【解决方案1】:

    经过更广泛的搜索后,我设法想出了这个解决方案 灵感来自"An Article"(我添加了我的触摸)

    代码:

    Dim app
    Dim db As Database, doc As Document
    Dim DBPath As String, MDWPath As String
    Dim UserName As String, Password As String
    Dim strRunCmd As String, msaccessPath As String
    
    Set app = CreateObject("Access.Application")
    
    DBPath = "D:\My Documents\myDb.mdb" 'full path of DB
    MDWPath = "D:\My Documents\Secured.mdw" 'full path of Workgroup file
    Username = "your User id" 'a legitimate user account (in the workgroup)
    Password = "user's password" 
    
    msaccessPath = "C:\Program Files\Office2003\Office11\msaccess.exe"
    
    strRunCmd = """" & msaccessPath & """ """ & DBPath & """ /WRKGRP """ & MDWPath & """ /User """ & UserName & """ /Pwd " & Password
    Shell strRunCmd, vbMaximizedFocus
    
    Do
        Set app = GetObject(DBPath)
        DoEvents
    Loop While app Is Nothing
    
    Set db = app.CurrentDb
    
    bkPath = "C:\Temp\bkDB\"
    With db.Containers("Forms")
       For Each doc In .Documents
           app.SaveAsText acForm, doc.Name, bkPath & doc.Name & ".frm"
       Next doc
    End With
    'repeat the loop to other object types such as reports, modules, macros
    
    'cleanup
    app.CloseCurrentDatabase
    app.Quit
    Set app = Nothing
    
    db.Close
    Set db = Nothing
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多