ACC2000: How to Display Microsoft PowerPoint Slides on a Form

ID: Q210075


The information in this article applies to:
  • Microsoft Access 2000

Advanced: Requires expert coding, interoperability, and multiuser skills.


SUMMARY

This article shows you how to display slides from Microsoft PowerPoint on a form in Microsoft Access. This technique uses Automation in Access to open a PowerPoint presentation and to link to the first slide. Viewing other slides is accomplished by changing the SourceItem property, which enables you to link to different slides.

NOTE: This OLE-linking approach is the most viable method for viewing Microsoft PowerPoint slides on a form in Microsoft Access. It is not possible to use Automation to run a Microsoft PowerPoint presentation directly from an object frame control on a form.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


MORE INFORMATION

NOTE: To use this technique, you must have both PowerPoint and Access installed on your computer. You also need to create a PowerPoint presentation (.ppt). In steps 7 and 9, replace the following file name with the name and path of your file:

C:\Program Files\Microsoft Office\Office\Pptexample.ppt
The following example creates a form with an unbound object frame control and five command buttons for linking to a PowerPoint presentation (.ppt) and for moving through its slides.

To display Microsoft PowerPoint slides on a form, follow these steps:
  1. In a new Access database, create a new form in Design view.


  2. Add the following five controls to the form:


  3. 
       Command button
       -------------------------
       Name: insertShow
       Caption: Get Presentation
       Enabled: Yes
       
       Command button
       -------------------------
       Name: frstSlide
       Caption: First Slide
       Enabled: No
       
       Command button
       -------------------------
       Name: nextSlide
       Caption: Next Slide
       Enabled: No
       
       Command button
       -------------------------
       Name: previousSlide
       Caption: Previous Slide
       Enabled: No
       
       Command button
       -------------------------
       Name: lastSlide
       Caption: Last Slide
       Enabled: No 
  4. Add an unbound object frame control to the form. In the Insert Object box, click the Create New button, select Bitmap Image as the Object Type, and then click OK. Note that the object frame appears as a blank space on the form.


  5. Display the property sheet for the unbound object frame, and then set its properties as follows:


  6. 
       Unbound Object Frame
       --------------------
       Name: pptFrame
       SizeMode: Zoom
       Enabled: Yes
       Locked: No 
  7. On the View menu, click Code to open the form module.


  8. Add the following code to the General Declarations section:
    
    ' Initialize variables.
    Const firstSlide = 1
    Dim arrSlideID() As Long
    Dim pptobj As Object
    Dim slideindex As Long, slidecount As Long 
    Add the following error handling procedure:


  9. 
    Sub ErrHandler()
    
       Dim strError As String
       Dim errObj As Error
       strError = " "
       If DBEngine.Errors.Count > 0 Then
          For Each errObj In DBEngine.Errors
             strError = strError & Format$(errObj.Number)
             strError = strError & " : " & errObj.Description
             strError = strError & " (" & errObj.Source & ") . "
             strError = strError & Chr$(13) & Chr$(10)
          Next
          MsgBox strError
       Else
          MsgBox "Error: " & Err & " " & Error
       End If
    
    End Sub 
  10. In the Object list click Form and click Load in the Procedure list, and then add the following code:

    NOTE: Replace the file name "C:\Program Files\Microsoft Office\Office\Pptexample.ppt" with the name and path of your Power Point Presentation file.


  11. 
    Private Sub Form_Load()
       On Error GoTo Form_Load_Error
       Dim i As Integer
       Dim holder As Long, present As Object
    
       ' Start Powerpoint and open an existing presentation.
       holder = Shell("c:\Program Files\Microsoft Office\Office\Powerpnt.exe")
       Set pptobj = CreateObject("PowerPoint.Application")
       Set present = pptobj.Presentations.Open _
          ("c:\Program Files\Microsoft Office\Office\Pptexample.ppt")
    
       ' Determine the number of slides in the presentation.
       slideCount = present.Slides.Count
       
       ' Fill an array with all Slide IDs.
       ReDim arrSlideID(1 To slideCount)
       For i = 1 To slideCount
         arrSlideID(i) = present.Slides(i).SlideID
       Next i
    
       ' Close the presentation.
       pptobj.Presentations _
          ("c:\Program Files\Microsoft Office\Office\Pptexample.ppt").Close
       Set present = Nothing
       Exit Sub
    
    Form_Load_Error:
       ErrHandler
       Exit Sub
    End Sub 
  12. Click Form in the Object list and click Unload in the Proc list, and then add the following code:


  13. 
    Private Sub Form_Unload(Cancel As Integer)
    On Error GoTo Form_Unload_Error
    
       ' Close Powerpoint.
       pptobj.Quit
    
    Exit Sub
    
    Form_Unload_Error:
       ErrHandler
       Exit Sub
    End Sub 
  14. Click insertShow in the Object list and click Click in the Proc list, and then add the following code.

    NOTE: Replace the file name "C:\Program Files\Microsoft Office\Office\Pptexample.ppt" with the name and path of your PowerPoint Presentation file.


  15. 
    Private Sub insertShow_Click()
       On Error GoTo insertShow_Click_Error
    
       ' Make object frame visible and enable "navigation" buttons.
       pptFrame.Visible = True
       frstslide.Enabled = True
       lastslide.Enabled = True
       nextslide.Enabled = True
       previousslide.Enabled = True
    
       ' Specify OLE Class, Type, SourceDoc, SourceItem and other
       ' properties.
       With pptFrame
          .Class = "Microsoft Powerpoint Slide" 
          .OLETypeAllowed = acOLELinked
          .SourceDoc = "c:\Program "_
          & "Files\Microsoft Office\Office\Pptexample.ppt"
          .SourceItem = arrSlideID(FIRSTSLIDE)
          .Action = acOLECreateLink
       End With
    
       ' Set slide index to the first slide.
       slideindex = FIRSTSLIDE
       frstSlide.setfocus
       insertShow.enabled=false
    
       Exit sub
    
    insertShow_Click_Error:
       ErrHandler
       Exit Sub
    End Sub 
  16. Click frstSlide in the Object list and click Click in the Proc list, and then add the following code:


  17. 
    Private Sub frstSlide_Click()
       On Error GoTo frstSlide_Click_Error
    
       ' Set SourceItem property to first slide and create a link.
       With pptFrame
          .SourceItem = arrSlideID(FIRSTSLIDE)
          .Action = acOLECreateLink
       End With
    
       slideindex = FIRSTSLIDE
    
       Exit Sub
    
    frstSlide_Click_Error:
       ErrHandler
       Exit Sub
    End Sub 
  18. Click nextSlide in the Object list and click Click in the Proc list, and then add the following code:


  19. 
    Private Sub nextSlide_Click()
       On Error GoTo nextSlide_Click_Error
    
       ' Determine if current slide is last slide.
       If slideindex < slidecount Then
          slideindex = slideindex + 1
    
          ' Set SourceItem property to next slide and create a link.
          With pptFrame
             .SourceItem = arrSlideID(slideindex)
             .Action = acOLECreateLink
          End With
       Else
          MsgBox "This is the last slide."
       End If
    
       Exit Sub
    
    nextSlide_Click_Error:
       ErrHandler
       Exit Sub
    End Sub
     
  20. Click previousSlide in the Object list and click Click in the Proc list, and then add the following code:


  21. 
    Private Sub previousSlide_Click()
       On Error GoTo previousSlide_Click_Error
    
       ' Determine if current slide is first slide.
       If slideindex > FIRSTSLIDE Then
          slideindex = slideindex - 1
    
          ' Set SourceItem property to previous slide and create a link.
          With pptFrame
             .SourceItem = arrSlideID(slideindex)
             .Action = acOLECreateLink
          End With
       Else
          MsgBox "This is the first slide."
       End If
    
       Exit Sub
    
    previousSlide_Click_Error:
       ErrHandler
       Exit Sub
    End Sub
     
  22. Click lastSlide in the Object list and click Click in the Proc list, and then add the following code:


  23. 
    Private Sub lastSlide_Click()
       On Error GoTo lastSlide_Click_Error
    
       ' Set SourceItem property to previous slide and create a link.
       With pptFrame
          .SourceItem = arrSlideID(slidecount)
          .Action = acOLECreateLink
       End With
    
       slideindex = slidecount
    
       Exit Sub
    
    lastSlide_Click_Error:
       ErrHandler
       Exit Sub
    End Sub
     
  24. Close and save the form module.


  25. Switch the form to Form view, and then click the insertShow ("Get Presentation") button.


Additional query words:

Keywords : kbinterop kbole kbdta AccCon IntpOlea KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 6, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.