Linking Powerpoint and Access through VBA?

☆樱花仙子☆ 提交于 2019-12-22 11:25:31

问题


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.

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?


回答1:


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

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

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.

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


来源:https://stackoverflow.com/questions/358722/linking-powerpoint-and-access-through-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!