通过 VBA 链接 Powerpoint 和 Access?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/358722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:07:14  来源:igfitidea点击:

Linking Powerpoint and Access through VBA?

ms-accessvbapowerpoint

提问by karlipoppins

I have a Powerpoint slide that contains textboxes. I would like to link those textboxes with a filtered view of a data table in Access.

我有一个包含文本框的 Powerpoint 幻灯片。我想将这些文本框与 Access 中数据表的过滤视图链接起来。

For ex, if I had a TaskList application in Access that displayed tasks with different priorities and affectations; is there a way to open that file, select that view, and filter it according to a vba (or other) onclick button event triggered from my Powerpoint presentation?

例如,如果我在 Access 中有一个 TaskList 应用程序,它显示具有不同优先级和影响的任务;有没有办法打开该文件,选择该视图,并根据从我的 Powerpoint 演示文稿触发的 vba(或其他)onclick 按钮事件对其进行过滤?

回答by Renaud Bompuis

It's certainly possible to get Access data from Powerpoint.

当然可以从 Powerpoint 获取 Access 数据。

You need to make sure you have the correct references set to theMicrosoft DAO Object Libraryin your VBA project.

您需要确保Microsoft DAO Object Library在 VBA 项目中设置了正确的引用。

Then, to populate your textbox in your PowerPoint presentation, you can call something like the following function, say, to return a string containing a list of Tasks matching the given TaskPriority.

然后,要在 PowerPoint 演示文稿中填充文本框,您可以调用类似以下函数的内容,例如,返回包含与给定 TaskPriority 匹配的任务列表的字符串。

Function GetTaskListFromAccess(taskPriority as Integer) as String
  Dim db As DAO.Database
  Dim rs As DAO.Recordset
  Dim listOfTasks as String

  Set db = DBEngine.OpenDatabase(“C:\my_database.accdb”)

  Set rs = db.OpenRecordset("SELECT * FROM TaskTable WHERE TaskPriority=" & _
                            taskPriority, dbOpenSnapshot)
  If not rs is nothing then
    If rs.RecordCount > 0 then
      With rs
        While Not .EOF
          if listOfTask = "" then 
            listOfTasks = !TaskName
           Else 
            listOfTasks = listOfTasks & vbCrLf & !TaskName
          End If
          .MoveNext
        Loop
      .Close
      End With
    End If
    Set rs = nothing
  End If
  Set db = nothing

  GetTaskListFromAccess = listOfTasks
End Function