Access Cookbook - Ken Getz [275]
" ORDER BY ObjectNumber, ParagraphNumber")
' Now walk through the list of text items, sticking
' them into the objects and applying properties.
Call InsertText(rst, objSlide)
rst.MoveFirst
Do Until rst.EOF
' Update the status information on the form.
With Forms("frmPowerPoint")
.UpdateDisplay rst("SlideNumber"), rst("Text")
.Repaint
End With
' No need to grab a reference to the shape each
' time through. Cache this value for later use.
If intObject <> rst("ObjectNumber") Then
intObject = rst("ObjectNumber")
Set pptShape = objSlide.Shapes(intObject)
End If
' Get a reference to the paragraph in question,
' then set its paragraph properties.
Set pptTextRange = pptShape.TextFrame.TextRange. _
Paragraphs(rst("ParagraphNumber"))
With pptTextRange.Font
If Not IsNull(rst("FontName")) Then
.Name = rst("FontName")
End If
If rst("FontSize") > 0 Then
.Size = rst("FontSize")
End If
If rst("Color") > 0 Then
.Color = rst("Color")
End If
' Set Yes/No/Use Default properties.
If rst("Shadow") <> conUseDefault Then
.Shadow = rst("Shadow")
End If
If rst("Bold") <> conUseDefault Then
.Bold = rst("Bold")
End If
If rst("Italic") <> conUseDefault Then
.Italic = rst("Italic")
End If
If rst("Underline") <> conUseDefault Then
.Underline = rst("Underline")
End If
End With
CreateSlideTextNext:
rst.MoveNext
Loop
CreateSlideText = True
ExitHere:
On Error Resume Next
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Function
HandleErrors:
CreateSlideText = False
Select Case Err.Number
Case conErrInvalidObjectIndex
Resume CreateSlideTextNext
Case Else
MsgBox "Error: " & Err.Description & " (" & Err.Number & ")",_
vbExclamation, "Create Slides Text"
End Select
Resume ExitHere
End Function
Comments
This solution uses only a small subset of the PowerPoint Automation interface. A great deal more functionality is available to you if you dig deep enough to find it. For example, you might want to support more of the text or bullet attributes than we've chosen, or dig into slide transitions, builds, and animation. Use the Object Browser (press F2 in a module window), shown in Figure 12-16, to help dig through the PowerPoint object model. You can work your way down through the hierarchy in an orderly fashion. For example, find the Application object in the left window, then browse through the right window until you find the Presentations collection. On the left, find the Presentations collection, and on the right, find the Add method. That's how we wrote this solution: by digging through the various objects, collections, methods, and properties that the Object Browser displays.
Figure 12-16. The Object Browser makes it possible to dig around in object models
You may also want to look at basGetTemplate, which includes a substantial amount of code dedicated to retrieving a list of all of PowerPoint's design templates. As it's installed, PowerPoint places the location of these templates in your registry. Two interesting issues are involved here: finding the name of the directory where the templates have been installed, and creating an array containing the names of the templates. Once the code creates the array, it uses the standard list-filling callback function mechanism, described in Chapter 7, to populate the combo box on the sample form. Though these topics are beyond the scope of this solution, you may find it useful to dig into the code, which has comments to help you through it.
12.8. Add a Contact and Send Email Through Outlook
Problem
You maintain an Access database full of contact information. You'd like to be able both to add contact information to your Outlook address book and to send email messages easily, using the email address stored in a particular row. How can you add these features to your form without forcing your users to load Outlook and work there?
Solution
Outlook provides a rich programming model, and it's easy for you to programmatically create contacts and send email. You'll find that solving these