Color scheme: Dark
You are here: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library API reference » WklBadge

WklBadge

WklBadge class

Signature

Dim myWklBadge As WklBadge
Set myWklBadge = Me!ControlName.Object

Summary

A count (“3”, “99+”) or a dot on a corner of another control of the same form section, as Outlook and Teams mark unread items: for Access buttons, labels, images and text boxes, which have no badge of their own.

Parameters

None

Remarks

Put the badge anywhere in the section, set Target to the name of the control it belongs to and Corner to the corner; in form view the badge places itself on that corner and follows the control when code moves it, resizes it or hides it. In design view the badge stays where it was drawn: moving it there would change the form.

Fill it in one of two ways:

  • By code: set Count, or Dot for a mark without a number.
  • Bound: set the badge's Control Source (ControlSource of the Access control) to a field or an expression, for example =DCount("*","tblSessions","IsOpen"). Access writes the value into Value on every record change; a bound badge never writes back and does not mark the record as changed.

What shows: a number shows as a count, above Max as “99+”; zero, a negative count, Null and text that is no number hide the badge (zero shows when HideZero is False). A dot badge shows without any value and follows a count when there is one; Null hides it as well, because “nothing known” must not look like “something new”.

Colors: the badge uses the accent colors of the kind (wskBad, red, by default), from Kind or per record from the field named in KindField; UseAccentColor and AccentColor set an own color, and the text then takes white or black, whichever contrasts more. In Windows high contrast the badge takes the system highlight colors.

The badge has the same pill and the same rules as the badges of WklButton (BadgeCount) and WklNavBar (SetBadge); those controls draw their badge themselves and need no WklBadge.

Screen readers hear “Sessions: 120” - the subject, then the full count, never “99+” - and, with Announce, every change. The subject is AccessibleText, else the caption of the target, else its name.

Limits:

  • Access draws a subform over every ActiveX control, so a badge on a subform stays hidden behind it; put it beside the subform.
  • Not in the detail section of a continuous form: Access creates one instance there, and a bound ActiveX control in the detail section keeps Access from opening the form. In the form header and footer the badge works.
  • The tabs of a tab control are not controls; a badge cannot follow a tab.

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
`Count`PropertyGets or sets the count shown.
`Value`PropertyGets or sets the bound value: Access writes the value of the Control Source into it on every record change.
`Dot`PropertyGets or sets whether the badge is a dot without a number.
`Max`PropertyGets or sets the highest count shown as a number.
`HideZero`PropertyGets or sets whether a count of zero hides the badge.
`Kind`PropertyGets or sets the kind whose accent colors the badge uses.
`KindField`PropertyGets or sets the name of a field or control of the form whose value is the kind of the badge.
`AccentColor`PropertyGets or sets an own fill color.
`UseAccentColor`PropertyGets or sets whether AccentColor replaces the color of the kind.
`Target`PropertyGets or sets the control the badge belongs to.
`Corner`PropertyGets or sets the corner of the target the badge stands on.
`OffsetX`PropertyGets or sets a shift of the badge to the right, in twips.
`OffsetY`PropertyGets or sets a shift of the badge downwards, in twips.
`AccessibleText`PropertyGets or sets what the badge counts, for screen readers.
`Announce`PropertyGets or sets whether screen readers announce every change of the badge.
`Clickable`PropertyGets or sets whether the badge takes clicks itself.
`TargetFound`PropertyGets whether the target was found the last time the badge looked for it.
`Refresh`MethodReads KindField again and places the badge on its target again, for example after code changed the field of the kind.
EventSummary
`Click`Occurs when the user clicks a badge whose Clickable is True, or a screen reader invokes it.

Code example

' The number of open sessions on the button cmdSessions.
Private Sub Form_Load()
    With Me!badSessions.Object
        .Target = "cmdSessions"
        .Corner = wbcTopRight
        .AccessibleText = "Open sessions"
        .Count = DCount("*", "tblSessions", "IsOpen")
    End With
End Sub

Inheritance

None

Count property

Signature

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

Summary

Gets or sets the count shown.

Parameters

None

Property value: Long – The count; values above Max show as “Max+”, zero and below hide the badge unless HideZero is False.

Remarks

Setting Count replaces Value. Reading it returns 0 for Null, for a badge without value and for a Value that is no number.

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

Value property

Signature

Property Get Value() As Variant
Property Let Value(RHS As Variant)

Summary

Gets or sets the bound value: Access writes the value of the Control Source into it on every record change.

Parameters

None

Property value: Variant – A number, a text holding a number, True (counts as 1), or Null (hides the badge).

Remarks

Before any value arrives, Value is Empty: a dot badge shows, a count badge stays hidden. The value is not stored with the form, and the badge never reports it back to Access.

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

Dot property

Signature

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

Summary

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

Parameters

None

Property value: Boolean – True: a dot; False (default): the count.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

Max property

Signature

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

Summary

Gets or sets the highest count shown as a number.

Parameters

None

Property value: Long – 1 or more; 99 (default) shows 120 as “99+”. Values below 1 raise wkeInvalidValue.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

HideZero property

Signature

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

Summary

Gets or sets whether a count of zero hides the badge.

Parameters

None

Property value: Boolean – True (default): hidden; False: “0” (or the dot).

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

Kind property

Signature

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

Summary

Gets or sets the kind whose accent colors the badge uses.

Parameters

None

Property value: `WklStatusKind` – A WklStatusKind; wskBad (red, default).

Remarks

With KindField the property returns the kind of the current record; the designed value applies when the field is empty or unknown. Values outside 0-4 raise wkeInvalidValue.

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

KindField property

Signature

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

Summary

Gets or sets the name of a field or control of the form whose value is the kind of the badge.

Parameters

None

Property value: String – A field of the form's record source or a control name; empty (default) for none. The field holds 0-4 or a name (neutral, ok, warn, bad, info); other values count as neutral.

Remarks

The field is read with every value and on Refresh. On UserForms there is no record; the designed Kind applies.

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

AccentColor property

Signature

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

Summary

Gets or sets an own fill color.

Parameters

None

Property value: OLE_COLOR – An OLE color, also a system color; it applies only while UseAccentColor is True.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

UseAccentColor property

Signature

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

Summary

Gets or sets whether AccentColor replaces the color of the kind.

Parameters

None

Property value: Boolean – True: AccentColor; False (default): the color of Kind.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

Target property

Signature

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

Summary

Gets or sets the control the badge belongs to.

Parameters

None

Property value: String – The name of a control on the same form (or UserForm); empty (default): the badge stays where it is.

Remarks

A name that does not exist raises no error; TargetFound then returns False and the badge stays where it is. The badge follows place, size and visibility of the target in form view, checked five times a second; it writes its own Left, Top, Width and Height only when they change.

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

Corner property

Signature

Property Get Corner() As WklBadgeCorner
Property Let Corner(RHS As WklBadgeCorner)

Summary

Gets or sets the corner of the target the badge stands on.

Parameters

None

Property value: `WklBadgeCorner` – A WklBadgeCorner; wbcTopRight (default). Values outside the enumeration raise wkeInvalidValue.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

OffsetX property

Signature

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

Summary

Gets or sets a shift of the badge to the right, in twips.

Parameters

None

Property value: Long – Twips; negative values shift to the left; 0 (default).

Remarks

The badge never moves beyond the top or left edge of its section: Access does not accept negative positions.

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

OffsetY property

Signature

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

Summary

Gets or sets a shift of the badge downwards, in twips.

Parameters

None

Property value: Long – Twips; negative values shift upwards; 0 (default).

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

AccessibleText property

Signature

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

Summary

Gets or sets what the badge counts, for screen readers.

Parameters

None

Property value: String – For example Open sessions; empty (default): the caption of the target (without &), or else its name.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

Announce property

Signature

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

Summary

Gets or sets whether screen readers announce every change of the badge.

Parameters

None

Property value: Boolean – True (default); False: the badge is read only when the user goes to it.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

Clickable property

Signature

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

Summary

Gets or sets whether the badge takes clicks itself.

Parameters

None

Property value: Boolean – False (default): a click on the badge goes to the control below it, usually the target; True: the badge raises Click.

Remarks

Access gives every ActiveX control TabStop = Yes, so Tab would stop on the badge. A badge with Clickable False is a mark, not something to operate: in form view it switches TabStop of its Access control off. With Clickable True, TabStop stays as designed.

Read/write.

Code example

None

Inheritance

Declared by WklBadge.

TargetFound property

Signature

Property Get TargetFound() As Boolean

Summary

Gets whether the target was found the last time the badge looked for it.

Parameters

None

Property value: Boolean – True when the target exists in form view; False without Target, in design view, or for a name that does not exist.

Remarks

Read-only.

Code example

None

Inheritance

Declared by WklBadge.

Refresh method

Signature

Sub Refresh()

Summary

Reads KindField again and places the badge on its target again, for example after code changed the field of the kind.

Parameters

None

Remarks

None

Code example

None

Inheritance

Declared by WklBadge.

Click event

Signature

Event Click()

Summary

Occurs when the user clicks a badge whose Clickable is True, or a screen reader invokes 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 WklBadge.

en/wiki/msaccess/comctl/api-reference/wklbadge.txt · Last modified: by Wolfgang van der Stille