Microsoft Office 2000/Visual Basic Programmer's Guide |
You add labels or check box controls to a Balloon object by using the Balloon object's Labels or Checkboxes property, respectively. (Note that label controls in Balloon objects are similar to option button controls.) You specify the text associated with a label or check box by using the control's Text property. You specify a single control by using an index number between 1 and 5, which represents the number of the label or check box control in the balloon. For example, the following sample shows one way to use label controls in a Balloon object:
With balBalloon
.Button = msoButtonSetNone
.Heading = "Balloon Object Example One"
.Text = "Select one of the following " _
& .Labels.Count & " options:"
.Labels(1).Text = "VBA is a powerful programming language."
.Labels(2).Text = "Office is a great development environment."
.Labels(3).Text = "The Assistant is cool!"
.Labels(4).Text = "Balloon objects are easy to use."
' Show the balloon.
intRetVal = .Show
' Save the selection made by the user.
If intRetVal > 0 Then
strChoice = "{cf 4}" & .Labels(intRetVal).Text & "{cf 0}"
Else
strChoice = ""
End If
End With
Set balBalloon = Assistant.NewBalloon
With balBalloon
.Text = "You selected option " & CStr(intRetVal) & ": '" _
& strChoice & "'"
.Show
End With
The preceding code fragment is part of the BalloonLabelControls procedure, which is available in the modAssistantTour module in AssistantTour.mdb in the ODETools\V9\Samples\OPG\Samples\CH06 subfolder on the Office 2000 Developer CD-ROM.
Note that when the balloon is displaying label controls, you don't need to also have OK or Cancel buttons because the balloon is dismissed as soon as any label control is selected, and the user can select only one control at a time. This is not the case when you use check box controls. The user can select more than one check box before dismissing the balloon, so your code should account for multiple selections. The next example shows one way to display check box controls and then identify the selections made by the user:
With balBalloon
.Button = msoButtonSetOK
.Heading = "Balloon Object Example Two"
.Text = "How many of the following " _
& .Checkboxes.Count & " statements do you agree with?"
.Checkboxes(1).Text = "VBA is a powerful programming language."
.Checkboxes(2).Text = "Office is a great development environment."
.Checkboxes(3).Text = "The Assistant is cool!"
.Checkboxes(4).Text = "Balloon objects are easy to use."
' Save the selection made by the user.
intRetVal = .Show
' Construct the string to display to the user based on the
' user's selections.
For Each chkBox In .Checkboxes
If chkBox.Checked = True Then
strChoice = strChoice & "{cf 4}" & chkBox.Text & "{cf 0}" & "' and '"
End If
Next chkBox
' Remove the trailing "' and '" from strChoice.
If Len(strChoice) <> 0 Then
strChoice = Left(strChoice, Len(strChoice) - 7)
End If
End With
' Create new Balloon object and display the user's choices.
Set balBalloon = Assistant.NewBalloon
With balBalloon
If intRetVal > 0 Or Len(strChoice) > 0 Then
.Text = "You selected '" & strChoice & "'."
Else
.Text = "You didn't make a selection."
End If
.Show
End With
The preceding code fragment is part of the BalloonCheckBoxControls procedure, which is available in the modAssistantTour module in AssistantTour.mdb in the ODETools\V9\Samples\OPG\Samples\CH06 subfolder on the Office 2000 Developer CD-ROM.