ACC2000: Example Using a Callback Procedure with Balloons
ID: Q209887
|
The information in this article applies to:
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).
SUMMARY
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.
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
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 Callback property of the balloon 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:
- Create a module and type the following line in the Declarations
section:
Option Explicit
- On the Tools menu, click References, and then click Microsoft Office 9.0 Object Library to add it as a reference. If you do not see it in the list, search your hard disk for the file, MSO9.DLL.
- Type the following procedure:
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
- The following is an example of a Callback procedure written to use with the procedure demonstrated above.
Note that the Callback procedure accepts three arguments: bln, iBtn, and iPriv. All Callback procedures that you write for use with balloons must accept these three arguments. The first argument, bln, defines the Balloon object that called the procedure. The second argument, iBtn, defines the value of the button or label that the user clicked. By using the iBtn argument, you can determine which button or label the user clicked. The third argument, iPriv, defines the value that uniquely identifies the balloon that called the procedure. The difference between the bln and iPriv arguments is that a programmer can use the iPriv argument to uniquely identify which balloon called the procedure. This allows a programmer to write one Callback procedure to use with all balloons, rather than having to write a separate Callback procedure for each Balloon.
-
Type the following procedure:
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
- To test these procedures, type the following line in the Immediate window, and then press ENTER:
OpenBalloon
Note that the Microsoft Office Assistant is displayed with a new balloon that contains multiple check boxes, labels, and buttons.
Click one or more of the check boxes and either a button or a label. Note that you receive message boxes indicating which check boxes you selected and which button or label you clicked.
REFERENCESFor more information about the Callback property, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the Help menu, type
Callback property in the Office Assistant or the Answer Wizard, and
then click Search to view the topic.
Additional query words:
asst
Keywords : kbprg kbdta AccCon PgmObj
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbinfo
|