繁体   English   中英

以 swarm 的形式打开 msaccess

[英]open msaccess as swarm

我们都知道 ms 访问不是多线程的,所以当 msacces 运行一个长查询时,它会挂起等待查询完成。 我想要的是打开一个新的访问实例来运行查询或在后台运行 vba 代码。 运行后,它需要在返回结果后自行安装(也许是 sql server 背景)

我以前在 excel 中看到过一些东西,但我想知道它是否可以在 access 中进行

excel 变体在这里 [excel swarm][1

更新

我使用以下代码打开访问

Dim appAccess As Object  
Set appAccess = CreateObject("Access.Application")  
Call appAccess.OpenCurrentDatabase( _ "D:\test.accdb")
appAccess.UserControl = True 
Set appAccess = Nothing

目标访问数据库预先格式化为一个循环,因为在访问打开时开始测试。 问题是源访问在目标访问的启动和运行期间挂起。 我可以使用计时器延迟启动然后它的工作。

主要问题是我如何统计未预先格式化的访问数据库,创建诸如 vba 代码、查询 odbc 连接等内容并在不挂起源数据库的情况下运行它。

你可以尝试从 shell 命令到另一个 VBA 主机,比如 excel,这可能会触发事件。 这是一个类,其中传入了 DB 路径和查询名称的属性,然后执行 GO,它使用 DBs ADO 连接的 Execute Complete 事件,我已对其进行编码以创建 Excel 实例并填充结果.

我没有像在某事中间那样完全测试过这个,但我会在午餐时进行全面测试并根据需要进行编辑,但这是一个起点

Option Explicit

Private WithEvents c As ADODB.Connection
Private strDBPath As String
Private strQueryToRun As String

Public Property Let DBPath(strPath As String)
    strDBPath = strPath
End Property

Public Property Let QueryToRun(strQuery As String)
    strQueryToRun = strQuery
End Property

Public Function GO()

Dim a As New Access.Application
a.OpenCurrentDatabase strDBPath, False

Set c = a.CurrentProject.Connection
c.EXECUTE strQueryToRun

a.CloseCurrentDatabase

a.Quit

Set a = Nothing

End Function

Private Sub c_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, _
                        ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)

    '   what to do with the results?

    Dim xl As New Excel.Application
    Dim xlWb As Excel.Workbook

    xl.Visible = True
    Set xlWb = xl.Workbooks.Add
    xlWb.Sheets(1).Range("a1").CopyFromRecordset pRecordset

End Sub

是的,这是可能的。

使用命令Shell打开另一个 Access 实例 - 并添加命令行参数 Access 以保存有关要运行哪些查询的信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM