The information in this article applies to:
- Microsoft Access versions 7.0, 97
SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article demonstrates how to display slides from Microsoft PowerPoint
7.0 or 97 on a form in Microsoft Access 7.0 or 97, respectively. This
technique uses OLE Automation in Microsoft 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.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
MORE INFORMATION
NOTE: You must have both Microsoft PowerPoint 7.0 or 97 and Microsoft
Access 7.0 or 97 installed on your computer in order to use this
technique. Also, you need to create a Microsoft PowerPoint presentation
(.ppt) in order to use the technique described in this article. In steps
7 and 9, replace the file name
C:\Msoffice\Powerpnt\Pptexample.ppt
with the name and path of your file.
The following example creates a form with an unbound object frame
control and five command buttons for linking to a Microsoft PowerPoint
presentation (.ppt) and for navigating through its slides.
To display Microsoft PowerPoint slides on a form, follow these steps:
- Open Microsoft Access and create a new form in Design view.
- Add the following five controls to the form:
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
- 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. In the Bitmap Image box, click "Exit & Return
to <formname>: Form" on the File menu. Note that the object frame
appears as a blank space on the form.
- Display the property sheet for the unbound object frame, and then set
its properties as follows:
Unbound Object Frame:
Name: pptFrame
SizeMode: Zoom
Enabled: Yes
Locked: No
- On the View menu, click Code to open the form module.
- Add the following code to the General Declarations section:
' Initialize variables.
Const FIRSTSLIDE = 256
Dim pptobj As Object
Dim slideindex As Long, slidecount As Long
Add an error handling procedure:
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
- Click Form in the Object list and click Load in the Procedure list,
and then add the following code:
NOTE: Replace the file name "C:\Msoffice\Powerpnt\Pptexample.ppt"
with the name and path of your Power Point Presentation file.
Private Sub Form_Load()
On Error GoTo Form_Load_Error
Dim holder As Long, present As Object
' Start Microsoft Powerpoint and open an existing presentation.
holder = Shell("c:\msoffice\powerpnt\powerpnt.exe")
Set pptobj = CreateObject("PowerPoint.Application")
Set present = pptobj.Presentations.Open _
("c:\msoffice\powerpnt\pptexample.ppt")
' Determine the number of slides in the presentation.
slidecount = present.Slides.Count - 1 + FIRSTSLIDE
' Close the presentation. Use only 1 of the following lines
'Office 97 Syntax
pptobj.Presentations _
("c:\msoffice\powerpnt\pptexample.ppt").Close
'Office 7.0 Syntax
present.Close
Set present = Nothing
Exit Sub
Form_Load_Error:
ErrHandler
Exit Sub
End Sub
- Click Form in the Object list and click Unload in the Proclist, and
then add the following code:
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
- 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:\Msoffice\Powerpnt\Pptexample.ppt"
with the name and path of your PowerPoint Presentation file.
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
'Use only 1 of the followin lines of code
.Class = "Microsoft Powerpoint Slide" 'Office 97 Syntax
.Class = "powerpoint.slide.7" 'Office 7.0 syntax
.OLETypeAllowed = acOLELinked
.SourceDoc = "c:\msoffice\powerpnt\pptexample.ppt"
.SourceItem = 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
- Click frstSlide in the Object list and click Click in the Proc list,
and then add the following code:
Private Sub frstSlide_Click()
On Error GoTo frstSlide_Click_Error
' Set SourceItem property to first slide and create a link.
With pptFrame
.SourceItem = FIRSTSLIDE
.Action = acOLECreateLink
End With
slideindex = FIRSTSLIDE
Exit Sub
frstSlide_Click_Error:
ErrHandler
Exit Sub
End Sub
- Click nextSlide in the Object list and click Click in the Proc list,
and then add the following code:
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 = slideindex
.Action = acOLECreateLink
End With
Else
MsgBox "This is the last slide."
End If
Exit Sub
nextSlide_Click_Error:
ErrHandler
Exit Sub
End Sub
- Click previousSlide in the Object list and click Click in the Proc
list, and then add the following code:
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 = slideindex
.Action = acOLECreateLink
End With
Else
MsgBox "This is the first slide."
End If
Exit Sub
previousSlide_Click_Error:
ErrHandler
Exit Sub
End Sub
- Click lastSlide in the Object list and click Click in the Proc list,
and then add the following code:
Private Sub lastSlide_Click()
On Error GoTo lastSlide_Click_Error
' Set SourceItem property to previous slide and create a link.
With pptFrame
.SourceItem = slidecount
.Action = acOLECreateLink
End With
slideindex = slidecount
Exit Sub
lastSlide_Click_Error:
ErrHandler
Exit Sub
End Sub
- Close and save the form module.
- Switch the form to Form view, and then click the insertShow ("Get
Presentation") button.
REFERENCES
For more information about using Microsoft PowerPoint for Windows 95
and Automation, please see the following article here in the Microsoft
Knowledge Base:
ARTICLE-ID: Q133789
TITLE : WT1229: Getting Started Controlling PowerPoint
Through OLE
Keywords : AutoGnrl kbinterop IntpOleA
Technology : kbole
Version : 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto