Farbschema: Dunkel
Sie befinden sich hier: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library API reference » WklButton

WklButton

WklButton class

Signature

Dim myWklButton As WklButton
Set myWklButton = Me!ControlName.Object

Summary

A command button in the look of current Office - caption with access key, glyph, four styles - that can also open a menu of its own with glyphs, shortcut texts, check marks, option groups and one submenu level, be split into a main part and a menu arrow, or show a row of segments of which one or several are selected.

Parameters

None

Remarks

For the developer the button works like the command button of Access: Caption with & before the access key letter, the Click event, and the properties Access gives every ActiveX control - Enabled, Visible, ControlTipText (the tooltip), TabStop - stay those of Access and are not repeated by the button. With Enabled set to No, Access removes the control's window; the button then draws itself gray and cannot be used.

Kind decides what the button is: wbkButton raises Click; wbkMenu opens the menu; wbkSplit raises Click on its main part and opens the menu on its arrow, for a main command with variants („Speichern“ with „Speichern unter“); wbkSegment shows its segments (AddSegment) side by side, for switching a view („Tag | Woche | Monat“), and raises Change when the user changes the selection. The menu is filled with AddMenuItem and AddMenuSeparator, either once in design view - the entries are stored with the form - or in code, for example in Form_Load or in DropDown just before it opens. Code that fills the menu should start with ClearMenu, because a key may occur only once; entries changed in form view do not make Access ask to save the form.

Click and MenuItemClick occur after the mouse button was released and the menu has closed, so an event procedure may show a message box, move the focus or close the form.

Keyboard: Space and Enter press the button; on a menu or split button Alt+Down and F4 open the menu. Segments are one tab stop, like an option group: Left, Right, Home and End move to another segment and select it; with MultiSelect they only move, and Space switches the segment. In the menu the arrow keys, Enter, Esc and the access keys of the entries work as in every Windows menu. Screen readers hear a button named by the caption without the &; a menu or split button reports whether its menu is open; segments are a list named by the caption whose items can be selected.

A count badge (BadgeCount, BadgeKind, BadgeDot) shows a number or a dot after the caption, or on the symbol of a button that shows only its symbol, in the colors of WklNavBar badges.

All properties, the menu and the segments can also be set without code: the designer opens from the row Custom [...] of the property sheet in design view (Opening the designer) and shows a preview of the button.

The button works on Excel and Word UserForms as well.

An ActiveX control: inserted into a form in design view (Form Design › Controls › ActiveX Controls); reports are not supported. VBA reaches it through the Object property of the control, where ControlName is the name of the control on the form.

MemberKindSummary
`Caption`PropertyGets or sets the text of the button.
`Glyph`PropertyGets or sets a symbol drawn with the caption.
`GlyphPosition`PropertyGets or sets where the symbol is drawn.
`Style`PropertyGets or sets the emphasis of the button.
`Kind`PropertyGets or sets what the button is.
`BackColor`PropertyGets or sets the color around the button.
`FontName`PropertyGets or sets the font of the caption.
`FontSize`PropertyGets or sets the size of the caption.
`AddMenuItem`MethodAdds an entry to the menu.
`AddMenuSeparator`MethodAdds a separator line to the menu, or to the submenu of Parent.
`RemoveMenuItem`MethodRemoves an entry together with its submenu.
`ClearMenu`MethodRemoves all entries and separators.
`MenuItemEnabled`PropertyGets or sets whether an entry can be chosen.
`MenuItemChecked`PropertyGets or sets whether an entry shows a check mark.
`MenuItemCount`PropertyReturns the number of entries, without separators.
`ShowMenu`MethodOpens the menu below the button, as a click on a menu button does, also for a button of kind wbkButton.
`AddSegment`MethodAdds a segment to a button of kind wbkSegment.
`RemoveSegment`MethodRemoves a segment.
`ClearSegments`MethodRemoves all segments.
`SegmentCount`PropertyReturns the number of segments.
`SegmentEnabled`PropertyGets or sets whether the user can select a segment.
`SegmentSelected`PropertyGets or sets whether a segment is selected.
`SelectedKey`PropertyGets or sets the selected segment.
`SelectedKeys`PropertyReturns the keys of all selected segments.
`MultiSelect`PropertyGets or sets whether several segments can be selected.
`BadgeCount`PropertyGets or sets the number in the button's count badge.
`BadgeKind`PropertyGets or sets the kind of the count badge, which sets its colors.
`BadgeDot`PropertyGets or sets whether the badge is a dot without a number.
`ColorScheme`PropertyGets or sets the color scheme the control draws in.
EventSummary
`Click`Occurs when the user presses a button of kind wbkButton, or the main part of a wbkSplit button: a click, Space or Enter while it has the focus, or a screen reader or test tool invoking it.
`DropDown`Occurs just before the menu opens, by click, key, ShowMenu or a screen reader.
`MenuItemClick`Occurs after the user chose an entry of the menu and the menu closed.
`Change`Occurs after the user changed the selection of the segments: by a click, the arrow keys, Space, or a screen reader selecting a segment.

Code example

' A menu button in the form header; the entries are set up when the form opens.
Private Sub Form_Load()
    With Me!btnAnsicht.Object
        .Kind = wbkMenu
        .Caption = "&Ansicht"
        .Glyph = "E8FD"
        .ClearMenu
        .AddMenuItem "tag", "&Tag", Group:="zeitraum", Checked:=True
        .AddMenuItem "woche", "&Woche", Group:="zeitraum"
        .AddMenuSeparator
        .AddMenuItem "export", "E&xportieren", "EDE1"
        .AddMenuItem "xlsx", "Excel-Arbeitsmappe", Parent:="export"
        .AddMenuItem "pdf", "PDF", Parent:="export"
        .AddMenuItem "delete", "&Delete all", "E74D", Enabled:=False, Reason:="Administrators only"
    End With
End Sub
 
Private Sub btnAnsicht_MenuItemClick(ByVal Key As String)
    Select Case Key
        Case "tag", "woche": Me.Filter = "Zeitraum = '" & Key & "'": Me.FilterOn = True
        Case "xlsx": DoCmd.OutputTo acOutputForm, Me.Name, acFormatXLSX
        Case "pdf": DoCmd.OutputTo acOutputForm, Me.Name, acFormatPDF
    End Select
End Sub

Inheritance

None

Caption property

Signature

Property Get Caption() As String
Property Let Caption(RHS As String)

Summary

Gets or sets the text of the button.

Parameters

None

Property value: String – Any text; an & before a letter marks the access key, && stands for an &. Default „Button“.

Remarks

Alt and the access key letter press the button from anywhere on the form, as on an Access command button: Click, or the menu opens for a menu button. The letter is underlined when Windows shows access keys (after Alt, or always, as set in Windows); segment buttons have no access key of their own. With GlyphPosition = wgpOnly the caption is not drawn; it remains the name screen readers hear, so set it also for buttons that show only a symbol.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

Glyph property

Signature

Property Get Glyph() As String
Property Let Glyph(RHS As String)

Summary

Gets or sets a symbol drawn with the caption.

Parameters

None

Property value: String – The hexadecimal code of a glyph of Segoe Fluent Icons (Windows 11) or Segoe MDL2 Assets (Windows 10), for example "E74E" (save) or "E721" (search); also with a prefix ("&HE74E", "U+E74E"); empty (default) for no symbol.

Remarks

Only codes from U+E000 to U+F8FF are accepted; others raise wkeInvalidValue. The symbol takes the color of the caption.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

GlyphPosition property

Signature

Property Get GlyphPosition() As WklGlyphPosition
Property Let GlyphPosition(RHS As WklGlyphPosition)

Summary

Gets or sets where the symbol is drawn.

Parameters

None

Property value: `WklGlyphPosition` – wgpLeft (default), wgpTop or wgpOnly.

Remarks

Without a symbol the caption is drawn alone whatever the value.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

Style property

Signature

Property Get Style() As WklButtonStyle
Property Let Style(RHS As WklButtonStyle)

Summary

Gets or sets the emphasis of the button.

Parameters

None

Property value: `WklButtonStyle` – wbsStandard (default), wbsPrimary, wbsSubtle or wbsDanger. Other values raise wkeInvalidValue.

Remarks

Use wbsPrimary for the one main command of a page, wbsSubtle for buttons in a command bar, and wbsDanger for commands that delete or discard. In Windows high contrast mode all styles use the system colors.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

Kind property

Signature

Property Get Kind() As WklButtonKind
Property Let Kind(RHS As WklButtonKind)

Summary

Gets or sets what the button is.

Parameters

None

Property value: `WklButtonKind` – wbkButton (default), wbkMenu, wbkSplit or wbkSegment. Other values raise wkeInvalidValue.

Remarks

Menu entries and segments are kept when Kind changes, so one control can be switched by code; a segment button ignores its menu, and the other kinds ignore their segments.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

BackColor property

Signature

Property Get BackColor() As OLE_COLOR
Property Let BackColor(RHS As OLE_COLOR)

Summary

Gets or sets the color around the button.

Parameters

None

Property value: OLE_COLOR – An OLE_COLOR; default the system color for windows (vbWindowBackground).

Remarks

Set it to the color of the section the button sits in, so the rounded corners and a subtle button at rest blend in.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

FontName property

Signature

Property Get FontName() As String
Property Let FontName(RHS As String)

Summary

Gets or sets the font of the caption.

Parameters

None

Property value: String – A font name; default "Segoe UI". An empty name raises wkeInvalidValue.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklButton.

FontSize property

Signature

Property Get FontSize() As Long
Property Let FontSize(RHS As Long)

Summary

Gets or sets the size of the caption.

Parameters

None

Property value: Long – Points from 6 to 72; default 9. Other values raise wkeInvalidValue.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklButton.

AddMenuItem method

Signature

Sub AddMenuItem(ByVal Key As String, ByVal Caption As String, Optional ByVal Glyph As String = "", Optional ByVal Shortcut As String = "", Optional ByVal Group As String = "", Optional ByVal Checked As Boolean = False, Optional ByVal Enabled As Boolean = True, Optional ByVal Reason As String = "", Optional ByVal Parent As String = "")

Summary

Adds an entry to the menu.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key MenuItemClick reports; not empty, unique without regard to case. A key that exists raises wkeDuplicateKey.
CaptionStringNo–The text; an & marks the access key. Empty raises wkeInvalidValue.
GlyphStringYes""A glyph code drawn before the text; empty if omitted.
ShortcutStringYes""A shortcut text shown at the right, for example „Ctrl+S“; empty if omitted. Display only: handle the key yourself, for example in Form_KeyDown with KeyPreview.
GroupStringYes""An option group; of the entries with the same group in the same menu, one is checked and shows a dot. Empty if omitted.
CheckedBooleanYesFalseTrue to show a check mark (in a group: to make this the checked entry); False if omitted.
EnabledBooleanYesTrueFalse to show the entry grayed out; True if omitted.
ReasonStringYes""The tooltip of the entry while it is disabled, for example why it cannot be used; empty if omitted.
ParentStringYes""The key of an entry whose submenu receives this one; empty if omitted. An unknown key raises wkeKeyNotFound; an entry of a submenu cannot be a parent (wkeInvalidValue), so there is one submenu level.

Remarks

Entries appear in the order they were added. An entry with entries below it opens its submenu and is never reported itself. Choosing an entry of an option group checks it before MenuItemClick occurs; a plain check mark is the application's to set with MenuItemChecked.

Code example

None

Inheritance

Declared by WklButton.

AddMenuSeparator method

Signature

Sub AddMenuSeparator(Optional ByVal Parent As String = "")

Summary

Adds a separator line to the menu, or to the submenu of Parent.

Parameters

NameTypeOptionalDefaultDescription
ParentStringYes""The key of the entry whose submenu receives the line; empty if omitted.

Remarks

None

Code example

None

Inheritance

Declared by WklButton.

RemoveMenuItem method

Signature

Sub RemoveMenuItem(ByVal Key As String)

Summary

Removes an entry together with its submenu.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key of the entry; an unknown key raises wkeKeyNotFound.

Remarks

None

Code example

None

Inheritance

Declared by WklButton.

ClearMenu method

Signature

Sub ClearMenu()

Summary

Removes all entries and separators.

Parameters

None

Remarks

None

Code example

None

Inheritance

Declared by WklButton.

Signature

Property Get MenuItemEnabled(ByVal Key As String) As Boolean
Property Let MenuItemEnabled(ByVal Key As String, RHS As Boolean)

Summary

Gets or sets whether an entry can be chosen.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key of the entry; an unknown key raises wkeKeyNotFound.

Property value: Boolean – True or False.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklButton.

Signature

Property Get MenuItemChecked(ByVal Key As String) As Boolean
Property Let MenuItemChecked(ByVal Key As String, RHS As Boolean)

Summary

Gets or sets whether an entry shows a check mark.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key of the entry; an unknown key raises wkeKeyNotFound.

Property value: Boolean – True or False. True on an entry of an option group clears the other entries of the group.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklButton.

Signature

Property Get MenuItemCount() As Long

Summary

Returns the number of entries, without separators.

Parameters

None

Property value: Long – 0 or more.

Remarks

Read-only.

Code example

None

Inheritance

Declared by WklButton.

ShowMenu method

Signature

Sub ShowMenu()

Summary

Opens the menu below the button, as a click on a menu button does, also for a button of kind wbkButton.

Parameters

None

Remarks

The call returns at once; the menu opens right after it, preceded by DropDown. In design view, where the button has no window, the call raises wkeNotConfigured. An empty menu does not open.

Code example

None

Inheritance

Declared by WklButton.

AddSegment method

Signature

Sub AddSegment(ByVal Key As String, ByVal Caption As String, Optional ByVal Glyph As String = "", Optional ByVal Enabled As Boolean = True)

Summary

Adds a segment to a button of kind wbkSegment.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key used by SelectedKey and SegmentSelected; not empty, unique without regard to case. A key that exists raises wkeDuplicateKey.
CaptionStringNo–The text; an & marks the access key. May be empty when Glyph is set.
GlyphStringYes""A glyph code drawn before the text; empty if omitted. Without caption and glyph the call raises wkeInvalidValue.
EnabledBooleanYesTrueFalse to show the segment grayed out; True if omitted.

Remarks

Segments share the width of the button equally, in the order they were added. Segments added in design view, and the selection set there, are stored with the form.

Code example

None

Inheritance

Declared by WklButton.

RemoveSegment method

Signature

Sub RemoveSegment(ByVal Key As String)

Summary

Removes a segment.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key; an unknown key raises wkeKeyNotFound.

Remarks

None

Code example

None

Inheritance

Declared by WklButton.

ClearSegments method

Signature

Sub ClearSegments()

Summary

Removes all segments.

Parameters

None

Remarks

None

Code example

None

Inheritance

Declared by WklButton.

SegmentCount property

Signature

Property Get SegmentCount() As Long

Summary

Returns the number of segments.

Parameters

None

Property value: Long – 0 or more.

Remarks

Read-only.

Code example

None

Inheritance

Declared by WklButton.

SegmentEnabled property

Signature

Property Get SegmentEnabled(ByVal Key As String) As Boolean
Property Let SegmentEnabled(ByVal Key As String, RHS As Boolean)

Summary

Gets or sets whether the user can select a segment.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key; an unknown key raises wkeKeyNotFound.

Property value: Boolean – True or False. A disabled segment keeps its selection; the keyboard skips it.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklButton.

SegmentSelected property

Signature

Property Get SegmentSelected(ByVal Key As String) As Boolean
Property Let SegmentSelected(ByVal Key As String, RHS As Boolean)

Summary

Gets or sets whether a segment is selected.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key; an unknown key raises wkeKeyNotFound.

Property value: Boolean – True or False. Without MultiSelect, True clears the other segments.

Remarks

Setting the selection by code raises no Change, as setting the value of an Access control raises no AfterUpdate.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

SelectedKey property

Signature

Property Get SelectedKey() As String
Property Let SelectedKey(RHS As String)

Summary

Gets or sets the selected segment.

Parameters

None

Property value: String – The key of the (first) selected segment; empty when none is selected. Setting a key selects only that segment, an empty string clears the selection; an unknown key raises wkeKeyNotFound.

Remarks

Setting it raises no Change.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

SelectedKeys property

Signature

Property Get SelectedKeys() As Variant

Summary

Returns the keys of all selected segments.

Parameters

None

Property value: Variant – A Variant holding an array of strings in segment order, empty (UBound < LBound) when none is selected.

Remarks

Read-only.

Code example

Debug.Print Join(Me!btnFormat.Object.SelectedKeys, ", ")

Inheritance

Declared by WklButton.

MultiSelect property

Signature

Property Get MultiSelect() As Boolean
Property Let MultiSelect(RHS As Boolean)

Summary

Gets or sets whether several segments can be selected.

Parameters

None

Property value: Boolean – False (default): one segment at most, and the user cannot clear the selection, as in an option group; True: each segment switches on and off.

Remarks

Switching MultiSelect off keeps the first selected segment only.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

BadgeCount property

Signature

Property Get BadgeCount() As Long
Property Let BadgeCount(RHS As Long)

Summary

Gets or sets the number in the button's count badge.

Parameters

None

Property value: Long – 0 (default) for no badge; above 99 the badge shows „99+“. Negative values raise wkeInvalidValue.

Remarks

Screen readers hear the caption with the whole number („Meldungen: 120“) and are told when it changes. Segment buttons show no badge.

Read/write.

Code example

Me!btnMeldungen.Object.BadgeCount = DCount("*", "tblMeldung", "Gelesen = False")

Inheritance

Declared by WklButton.

BadgeKind property

Signature

Property Get BadgeKind() As WklStatusKind
Property Let BadgeKind(RHS As WklStatusKind)

Summary

Gets or sets the kind of the count badge, which sets its colors.

Parameters

None

Property value: `WklStatusKind` – wskBad (default), wskNeutral, wskOk, wskWarn, wskInfo or wskMuted. Other values raise wkeInvalidValue.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklButton.

BadgeDot property

Signature

Property Get BadgeDot() As Boolean
Property Let BadgeDot(RHS As Boolean)

Summary

Gets or sets whether the badge is a dot without a number.

Parameters

None

Property value: Boolean – True: a dot, shown whatever BadgeCount is, for example for „something new“; False (default).

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklButton.

ColorScheme property

Signature

Property Get ColorScheme() As WklColorScheme
Property Let ColorScheme(RHS As WklColorScheme)

Summary

Gets or sets the color scheme the control draws in.

Parameters

None

Property value: `WklColorScheme` – wcoAutomatic (default), wcoLight, wcoDark or wcoHighContrast.

Remarks

wcoAutomatic follows, in this order, Windows high contrast mode, then the color set of the database design (Access: Design › Themes or Colors), and draws light when the database has no design or the control is on an Excel or Word UserForm. Office's own design setting and the Windows app mode are not followed: a database looks the same on every PC. In high contrast mode the control always uses the system colors. The scheme colors the space around the button, the button in each style and state (light: the Fluent 2 colors; dark: the Fluent 2 dark colors; a database color set: its surface, border and text, Primary in its accent 1; Danger stays red), the focus ring and the drop-down menu; a BackColor you set wins over the scheme. Every text keeps a contrast of at least 4.5:1. The control reads the database design after it is first drawn, never while Access draws the form, and again when the form opens anew. The value is saved with the form.

Read/write.

Code example

None

Inheritance

Declared by WklButton.

Click event

Signature

Event Click()

Summary

Occurs when the user presses a button of kind wbkButton, or the main part of a wbkSplit button: a click, Space or Enter while it has the focus, or a screen reader or test tool invoking it.

Parameters

None

Remarks

In a form module: Private Sub <ControlName>_Click(...). Parameters passed by reference can be changed by the procedure.

Code example

None

Inheritance

Declared by WklButton.

Signature

Event DropDown()

Summary

Occurs just before the menu opens, by click, key, ShowMenu or a screen reader.

Parameters

None

Remarks

Adjust the entries here, for example enable them according to the current record. If the menu is empty afterwards, it does not open.

In a form module: Private Sub <ControlName>_DropDown(...). Parameters passed by reference can be changed by the procedure.

Code example

None

Inheritance

Declared by WklButton.

Signature

Event MenuItemClick(ByVal Key As String)

Summary

Occurs after the user chose an entry of the menu and the menu closed.

Parameters

NameTypeOptionalDefaultDescription
KeyStringNo–The key of the chosen entry.

Remarks

Disabled entries, separators and entries that open a submenu never occur. Closing the menu without a choice (Esc, a click elsewhere) raises no event.

In a form module: Private Sub <ControlName>_MenuItemClick(...). Parameters passed by reference can be changed by the procedure.

Code example

None

Inheritance

Declared by WklButton.

Change event

Signature

Event Change()

Summary

Occurs after the user changed the selection of the segments: by a click, the arrow keys, Space, or a screen reader selecting a segment.

Parameters

None

Remarks

Read the selection in the event with SelectedKey or SelectedKeys. Clicking the selected segment without MultiSelect changes nothing and raises no event; code that sets the selection raises none either.

In a form module: Private Sub <ControlName>_Change(...). Parameters passed by reference can be changed by the procedure.

Code example

Private Sub btnZeitraum_Change()
    Me.Filter = "Zeitraum = '" & Me!btnZeitraum.Object.SelectedKey & "'"
    Me.FilterOn = True
End Sub

Inheritance

Declared by WklButton.

en/wiki/msaccess/comctl/api-reference/wklbutton.txt · Zuletzt geändert: von Wolfgang van der Stille