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

WklTokenBox

WklTokenBox class

Signature

Dim myWklTokenBox As WklTokenBox
Set myWklTokenBox = Me!ControlName.Object

Summary

A box of tokens (tags, roles, keywords): each value is a chip with a remove button, new values are typed into the box with suggestions as you type.

Parameters

None

Remarks

Use the token box where a record has a short list of values of one kind - the roles of a user, the tags of a document, the e-mail recipients of a rule. It binds like an Access subform: RecordSource names the child table (or query), ValueField the field that holds one value, and LinkChildFields/LinkMasterFields connect the child rows to the record of the form, also with several fields. Each token is one child row. Adding a token inserts its row at once, removing it deletes the row at once, as a subform saves its rows; there is no pending state and no Undo.

For the box to follow the record, set its Control Source (ControlSource of the Access control) to the key field of the form: Access writes it into MasterValue on every record change, and the box reads the master values from LinkMasterFields and loads the tokens of that record. The box also checks the master values four times a second, so it follows the record even without a Control Source. On a new record that is not saved yet, the box shows no tokens and refuses input until the record has its key, as a subform does.

Without RecordSource the box is unbound: Text holds the values, joined by Separator, and code saves them where it wants.

In design view, Properties of the control opens its designer with the pages Data (child table and link), Suggestions and rules, and Appearance (caption, colors, font, a preview with sample values); OK refuses a pattern that does not compile, an empty separator, a bound box without value field and link fields of different number. A walkthrough: How to: Keep several values of a record as tokens.

The user types a value and confirms it with Enter, a one-character separator, or by picking a suggestion (Down opens the list); leaving the box with text also adds it, Esc clears the input. Backspace in an empty input selects and then removes the last token; Left and Right move between tokens, Delete removes the selected one. Suggestions come from SuggestionList and SuggestionSource; AllowFreeText = False accepts only suggested values. Pattern and ValidationText check each new value, and a value that is already a token is refused. A refused value stays in the input, and the reason appears below the box and in ErrorText.

Enabled, Locked, Visible, Tab Stop, and ControlTip Text are the properties Access gives every ActiveX control. A locked box, a form with Allow Edits set to No, and the design view show the tokens without remove buttons and refuse input.

Screen readers hear the box as a list named by Caption (or the control name); each token is a list item with a button “entfernen” that a screen reader can invoke.

A list column can show the same chips read-only: wedTokens as Editor of a column of WklGrid or WklTreeList, over a field that joins the values of the child rows into one text.

Do not use the multivalued fields of Access for this: they exist only in Access tables (not on SQL Server or over ODBC), and Access saves them with the parent record. A child table works with every back end.

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
`Text`PropertyGets or sets all tokens as one text.
`Separator`PropertyGets or sets the separator of Text and SuggestionList.
`RecordSource`PropertyGets or sets the child table or query that holds one row per token.
`ValueField`PropertyGets or sets the field of the child row that holds the value of the token.
`LinkChildFields`PropertyGets or sets the fields of the child rows that link them to the record of the form.
`LinkMasterFields`PropertyGets or sets the fields or controls of the form whose values the child rows must match.
`MasterValue`PropertyGets or sets the value Access writes into the box on every record change.
`SuggestionSource`PropertyGets or sets a table, query or SQL statement whose first column lists the suggestions.
`SuggestionList`PropertyGets or sets suggestions as a value list.
`AllowFreeText`PropertyGets or sets whether any typed value can become a token.
`Pattern`PropertyGets or sets a regular expression each new value must match as a whole.
`ValidationText`PropertyGets or sets the message when Pattern refuses a value.
`MatchCase`PropertyGets or sets whether tokens that differ only in case are different.
`Caption`PropertyGets or sets the name of the box in messages and for screen readers.
`BackColor`PropertyGets or sets the background color.
`ForeColor`PropertyGets or sets the color of the token text and the input.
`FontName`PropertyGets or sets the font of the tokens and the input.
`FontSize`PropertyGets or sets the font size in points.
`Count`PropertyGets the number of tokens.
`Item`PropertyGets the value of a token.
`AddToken`MethodAdds a token by code.
`RemoveToken`MethodRemoves a token by code.
`Requery`MethodReads the tokens and the suggestions again.
`ErrorText`PropertyGets the reason why the last value was refused.
`ListRows`PropertyGets or sets how many suggestions the list shows at most.
`ColorScheme`PropertyGets or sets the color scheme the control draws in.
EventSummary
`TokenAdding`Occurs before the user adds a token.
`TokenAdded`Occurs after the user has added a token; a bound box has inserted its child row.
`TokenRemoving`Occurs before the user removes a token.
`TokenRemoved`Occurs after the user has removed a token; a bound box has deleted its child row.
`Change`Occurs after the user has added or removed a token, after TokenAdded or TokenRemoved.
`DataError`Occurs when the child rows or the suggestions cannot be read or written.

Code example

None

Inheritance

None

Text property

Signature

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

Summary

Gets or sets all tokens as one text.

Parameters

None

Property value: String – The values joined by Separator and one blank, for example Red; Green; Blue. When set, the text is split at Separator, blanks around each value are removed, empty values and repeated values are dropped.

Remarks

Setting Text of a bound box writes only the differences: it deletes the child rows of tokens that are no longer in the text and inserts rows for the new ones, without the events TokenAdding … Change. The values are not checked against Pattern or AllowFreeText; code is trusted, as with AddToken and RemoveToken. If writing a row fails, DataError occurs and the box reads the tokens from the table again. On a new record that is not saved yet, a linked box writes nothing.

Read/write.

Code example

Me!tokRollen.Object.Text = "Leser; Autor"

Inheritance

Declared by WklTokenBox.

Separator property

Signature

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

Summary

Gets or sets the separator of Text and SuggestionList.

Parameters

None

Property value: String – Any text that is not empty; ; (default). An empty text raises wkeInvalidValue.

Remarks

Typing a separator of one character in the box also confirms the value before it. Choose a character that never occurs in a value.

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

RecordSource property

Signature

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

Summary

Gets or sets the child table or query that holds one row per token.

Parameters

None

Property value: String – The name of a table or query, or a SQL statement; empty (default) for an unbound box.

Remarks

The source must be updatable: the box inserts and deletes its rows. A linked SQL Server table needs a primary key or a unique index, as for any edit in Access. The rows are read and written through the database of the form (DAO), so linked ODBC tables work as local ones. Messages of the back end, for example a violated constraint, reach DataError.

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

ValueField property

Signature

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

Summary

Gets or sets the field of the child row that holds the value of the token.

Parameters

None

Property value: String – The name of a field of RecordSource.

Remarks

A row whose field is Null or an empty text gives no token.

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

LinkChildFields property

Signature

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

Summary

Gets or sets the fields of the child rows that link them to the record of the form.

Parameters

None

Property value: String – Field names separated by ;, as for a subform; empty (default) shows all rows of RecordSource.

Remarks

A new token's row gets the master values in these fields. The number and order of the fields must match LinkMasterFields.

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

LinkMasterFields property

Signature

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

Summary

Gets or sets the fields or controls of the form whose values the child rows must match.

Parameters

None

Property value: String – Field or control names of the form separated by ;, as for a subform.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

MasterValue property

Signature

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

Summary

Gets or sets the value Access writes into the box on every record change.

Parameters

None

Property value: Variant – Any value.

Remarks

MasterValue is the bound property of the box: set the Control Source of the Access control to the key field of the form, so Access writes it on every record change. It is only the signal; the values that select the child rows always come from LinkMasterFields. When they have changed, the box loads the tokens of the new record.

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

SuggestionSource property

Signature

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

Summary

Gets or sets a table, query or SQL statement whose first column lists the suggestions.

Parameters

None

Property value: String – The name of a table or query, or a SQL statement; empty (default) for none.

Remarks

The source is read once, when the suggestions are first needed, and again on Requery. The suggestions of SuggestionList come first. A value that is already a token is not suggested again.

Read/write.

Code example

Me!tokRollen.Object.SuggestionSource = "SELECT Rolle FROM tblRolle ORDER BY Rolle"

Inheritance

Declared by WklTokenBox.

SuggestionList property

Signature

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

Summary

Gets or sets suggestions as a value list.

Parameters

None

Property value: String – Values joined by Separator, for example Leser; Autor; Admin; empty (default) for none.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

AllowFreeText property

Signature

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

Summary

Gets or sets whether any typed value can become a token.

Parameters

None

Property value: Boolean – True (default) accepts any value; False accepts only a value of the suggestions.

Remarks

With False, a typed value that matches a suggestion becomes a token in the spelling of the suggestion.

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

Pattern property

Signature

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

Summary

Gets or sets a regular expression each new value must match as a whole.

Parameters

None

Property value: String – A .NET regular expression; empty (default) for none. An expression that does not compile raises wkeInvalidValue.

Remarks

Read/write.

Code example

Me!tokTags.Object.Pattern = "[a-z0-9-]+"
Me!tokTags.Object.ValidationText = "Nur Kleinbuchstaben, Ziffern und Bindestrich."

Inheritance

Declared by WklTokenBox.

ValidationText property

Signature

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

Summary

Gets or sets the message when Pattern refuses a value.

Parameters

None

Property value: String – Any text; empty (default) for the generated message.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

MatchCase property

Signature

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

Summary

Gets or sets whether tokens that differ only in case are different.

Parameters

None

Property value: Boolean – False (default) treats Rot and rot as the same token, as Access compares text; True tells them apart.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

Caption property

Signature

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

Summary

Gets or sets the name of the box in messages and for screen readers.

Parameters

None

Property value: String – Any text; empty (default) for the control name.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

BackColor property

Signature

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

Summary

Gets or sets the background color.

Parameters

None

Property value: OLE_COLOR – An OLE color; the window background of Windows (vbWindowBackground, default).

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

ForeColor property

Signature

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

Summary

Gets or sets the color of the token text and the input.

Parameters

None

Property value: OLE_COLOR – An OLE color; the window text of Windows (vbWindowText, default).

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

FontName property

Signature

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

Summary

Gets or sets the font of the tokens and the input.

Parameters

None

Property value: String – The name of an installed font; “Segoe UI” (default). An empty name raises wkeInvalidValue.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

FontSize property

Signature

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

Summary

Gets or sets the font size in points.

Parameters

None

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

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

Count property

Signature

Property Get Count() As Long

Summary

Gets the number of tokens.

Parameters

None

Property value: Long – 0 or more.

Remarks

Read-only.

Code example

None

Inheritance

Declared by WklTokenBox.

Item property

Signature

Property Get Item(ByVal Index As Long) As String

Summary

Gets the value of a token.

Parameters

NameTypeOptionalDefaultDescription
IndexLongNo–The position, from 0 to Count - 1. Another position raises wkeInvalidValue.

Property value: String – The value of the token.

Remarks

Read-only.

Code example

Dim i As Long
For i = 0 To Me!tokRollen.Object.Count - 1
    Debug.Print Me!tokRollen.Object.Item(i)
Next

Inheritance

Declared by WklTokenBox.

AddToken method

Signature

Function AddToken(ByVal Value As String) As Boolean

Summary

Adds a token by code.

Parameters

NameTypeOptionalDefaultDescription
ValueStringNo–The value to add.

Return value: Boolean – The value to add.

Remarks

The value passes the same checks as typed input (Pattern, AllowFreeText, an existing token); ErrorText names the reason of a refusal. A bound box inserts the child row; a linked box on a new record that is not saved yet refuses, because the row would belong to no record. The events TokenAdding, TokenAdded and Change do not occur.

Code example

None

Inheritance

Declared by WklTokenBox.

RemoveToken method

Signature

Function RemoveToken(ByVal Value As String) As Boolean

Summary

Removes a token by code.

Parameters

NameTypeOptionalDefaultDescription
ValueStringNo–The value to remove; compared as MatchCase says.

Return value: Boolean – The value to remove; compared as MatchCase says.

Remarks

A bound box deletes the child rows with this value. The events TokenRemoving, TokenRemoved and Change do not occur.

Code example

None

Inheritance

Declared by WklTokenBox.

Requery method

Signature

Sub Requery()

Summary

Reads the tokens and the suggestions again.

Parameters

None

Remarks

Use it after code has changed the child table or the suggestion source behind the box's back.

Code example

None

Inheritance

Declared by WklTokenBox.

ErrorText property

Signature

Property Get ErrorText() As String

Summary

Gets the reason why the last value was refused.

Parameters

None

Property value: String – The message also shown below the box; empty after a value was accepted.

Remarks

Read-only.

Code example

None

Inheritance

Declared by WklTokenBox.

ListRows property

Signature

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

Summary

Gets or sets how many suggestions the list shows at most.

Parameters

None

Property value: Long – 1 to 50; 8 (default). Other values raise wkeInvalidValue.

Remarks

Read/write.

Code example

None

Inheritance

Declared by WklTokenBox.

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 background and text (while BackColor and ForeColor keep the system defaults), the tokens, the selection and the suggestion list; 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 WklTokenBox.

TokenAdding event

Signature

Event TokenAdding(ByVal Value As String, ByRef Cancel As Integer)

Summary

Occurs before the user adds a token.

Parameters

NameTypeOptionalDefaultDescription
ValueStringNo–The value, already checked against the rules of the box.
CancelInteger (by reference)No–Set to True to refuse the value; it stays in the input.

Remarks

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

Code example

None

Inheritance

Declared by WklTokenBox.

TokenAdded event

Signature

Event TokenAdded(ByVal Value As String)

Summary

Occurs after the user has added a token; a bound box has inserted its child row.

Parameters

NameTypeOptionalDefaultDescription
ValueStringNo–The value of the new token.

Remarks

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

Code example

None

Inheritance

Declared by WklTokenBox.

TokenRemoving event

Signature

Event TokenRemoving(ByVal Value As String, ByRef Cancel As Integer)

Summary

Occurs before the user removes a token.

Parameters

NameTypeOptionalDefaultDescription
ValueStringNo–The value of the token.
CancelInteger (by reference)No–Set to True to keep the token.

Remarks

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

Code example

None

Inheritance

Declared by WklTokenBox.

TokenRemoved event

Signature

Event TokenRemoved(ByVal Value As String)

Summary

Occurs after the user has removed a token; a bound box has deleted its child row.

Parameters

NameTypeOptionalDefaultDescription
ValueStringNo–The value of the removed token.

Remarks

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

Code example

None

Inheritance

Declared by WklTokenBox.

Change event

Signature

Event Change()

Summary

Occurs after the user has added or removed a token, after TokenAdded or TokenRemoved.

Parameters

None

Remarks

It does not occur for Text, AddToken, RemoveToken or a record change. Like all events of an ActiveX control it needs a procedure in the form's module.

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

Code example

None

Inheritance

Declared by WklTokenBox.

DataError event

Signature

Event DataError(ByVal DataErr As Long, ByVal Description As String, ByRef Response As Integer)

Summary

Occurs when the child rows or the suggestions cannot be read or written.

Parameters

NameTypeOptionalDefaultDescription
DataErrLongNo–The error code (HRESULT).
DescriptionStringNo–The message, including the text of the back end.
ResponseInteger (by reference)No–Leave it to show the message (2, acDataErrDisplay); set it to 0 (acDataErrContinue) to suppress it.

Remarks

A token whose row could not be inserted is not added, a token whose row could not be deleted stays. Errors while reading show no message box: the box stays empty, and the event is the only report.

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

Code example

None

Inheritance

Declared by WklTokenBox.

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