【问题标题】:Connect Visio document to Access database将 Visio 文档连接到 Access 数据库
【发布时间】:2016-03-15 01:04:39
【问题描述】:

我想在我的 Visio 文档中添加一个 Access 数据库。 MSN 示例显示了连接到 Excel 文档的字符串。我将使用什么来连接 Access DB?

我正在使用:

微软 Visio 2013
Microsoft Access 2013
Microsoft Windows 7 企业版。

数据库位置:

C:\Users\j.Smith\Desktop\access_file.mdb

我的脚本:

Public Sub AddDataRecordset_Example() 

    Dim strConnection As String 
    Dim strCommand As String 
    Dim strOfficePath As String 
    Dim vsoDataRecordset As Visio.DataRecordset 

    strOfficePath = Visio.Application.Path     
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _ 
                   & "User ID=Admin;" _ 
                   & "Data Source=" + strOfficePath + "SAMPLES\1033\ORGDATA.XLS;" _ 
                   & "Mode=Read;" _ 
                   & "Extended Properties=""HDR=YES;IMEX=1;MaxScanRows=0;Excel 12.0;"";" _ 
                   & "Jet OLEDB:Engine Type=34;" 

    strCommand = "SELECT * FROM [Sheet1$]" 

    Set vsoDataRecordset = ActiveDocument.DataRecordsets.Add(strConnection, strCommand, 0, "Org Data") 

End Sub

【问题讨论】:

    标签: vba ms-access visio


    【解决方案1】:

    应该这样做:

    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "User ID=Admin;" & _
        "Data Source=" & accessFileName & ";" & _
        "Mode=Read;" & _
        "Extended Properties="""";" & _
        "Jet OLEDB:System database="""";" & _
        "Jet OLEDB:Engine Type=6;" & _
        "Jet OLEDB:Database Locking Mode=0;"
    strCommand = "SELECT * FROM `tablename`"
    

    注意表名周围的单引号。

    另外,仅供参考,我一直觉得以下网站非常有用:ConnectionStrings

    【讨论】:

      猜你喜欢
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多