ACC97: Example Using a Callback Procedure with BalloonsID: Q167842
|
This article shows you how to use the Callback property of a Balloon
object to determine which check boxes a user selected, or which label or
button a user clicked, and then to respond to that selection.
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 the "Building
Applications with Microsoft Access 97" manual.
NOTE: A demonstration of the technique used in this article can be seen
in the sample file, FrmSmp97.exe. For information about how to obtain
this sample file, please see the following article in the Microsoft
Knowledge Base:
Q175066 ACC97: Microsoft Access 97 Sample Forms Available on MSL
A balloon is the area in which the Microsoft Office Assistant displays
headings and text, similar to a message box. In addition to headings and
text, a balloon may contain other types of controls, such as check boxes,
buttons, and labels which are similar to option buttons.
To determine which label or button a user clicked, or which check boxes a
user selected in a balloon, you must create a Callback procedure and set
the balloon's Callback property to the name of that procedure. A Callback
procedure is a procedure that runs whenever a modeless balloon is
displayed.
To display a balloon with multiple buttons, labels, and check boxes, follow
these steps:
Option Explicit
Sub OpenBalloon()
Dim offBalloon As Office.Balloon
Set offBalloon = Application.Assistant.NewBalloon
With offBalloon
' Show the Office Assistant.
.Parent.Visible = True
' Set the heading and text of the balloon.
.Heading = "Welcome to the Microsoft Office 97 Assistant!"
.Text = "Click one or more of the check boxes below, and " _
& "also click either a label or a button."
' Make the balloon modeless.
.Mode = msoModeModeless
' Display the Back, Next, and Close Buttons.
' To determine the constants for other buttons you can place
' on a balloon, view the Microsoft Office 8.0 Object library
' in the Object Browser.
.Button = msoButtonSetBackNextClose
' Display two check boxes.
.Checkboxes(1).Text = "Checkbox 1"
.Checkboxes(2).Text = "Checkbox 2"
' Display two labels.
.Labels(1).Text = "Label 1"
.Labels(2).Text = "Label 2"
' Define which Callback procedure to run.
.Callback = "WhichButton"
.Show
End With
End Sub
Sub WhichButton(bln As Balloon, iBtn As Long, iPriv As Long)
Dim cBox As Office.BalloonCheckbox
bln.Close
For Each cBox In bln.Checkboxes
If cBox.Checked Then
MsgBox "Selected " & cBox.Item
End If
Next
Select Case iBtn
Case 1
MsgBox "Clicked Label 1"
Case 2
MsgBox "Clicked Label 2"
Case msoBalloonButtonBack
MsgBox "Clicked Back Button"
Case msoBalloonButtonClose
MsgBox "Clicked Close Button"
Case msoBalloonButtonNext
MsgBox "Clicked Next Button"
End Select
End Sub
OpenBalloonNote that the Microsoft Office Assistant is displayed with a new balloon that contains multiple check boxes, labels, and buttons.
For more information about using the Callback property with the Microsoft Office Assistant, search the Help Index for "Callback property."
Additional query words: asst
Keywords : kbprg PgmObj
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: August 5, 1999