WklSpinEdit
WklSpinEdit class
Signature
Dim myWklSpinEdit As WklSpinEdit Set myWklSpinEdit = Me!ControlName.Object
Summary
A number with up and down arrows, bound like an Access text box - limits, a step, decimal places and an optional unit after the number, for example a session length in hours or the lifetime of a key in days.
Parameters
None
Remarks
Bind it through Control Source like a text box: Access writes the field into Value on every record change. The first change of the user asks Access whether the field may be edited; a locked control (Locked) or a form without edits (AllowEdits = False) refuses. Every change marks the record as changed, and Access writes the value into the field when the record is saved at the latest.
The arrows, Up/Down (one Step) and Page Up/Page Down (ten steps) never leave MinValue and MaxValue; the mouse wheel steps while the field has the focus. A typed number is taken while it is valid. When the user leaves the field with a text that is no number or lies outside the limits, the value the field had when the user entered it comes back and InvalidEntry occurs - the control shows no message box of its own, so the form decides how to tell the user. Esc puts back the value before the user's first change; a second Esc goes to Access.
Unit is display text: the field keeps the number in that unit. Enabled, Locked, Visible, TabStop and the tooltip (ControlTipText) are Access's own properties of the control.
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.
| Member | Kind | Summary |
|---|---|---|
| `Value` | Property | Gets or sets the value: the number, or Null for an empty field. |
| `Caption` | Property | Gets or sets the name screen readers hear for the field. |
| `MinValue` | Property | Gets or sets the smallest value the user can enter. |
| `MaxValue` | Property | Gets or sets the largest value the user can enter. |
| `Step` | Property | Gets or sets the change of one press of an arrow or Up/Down. |
| `DecimalPlaces` | Property | Gets or sets the decimal places a value is rounded to and shown with. |
| `Unit` | Property | Gets or sets the unit shown after the number. |
| `BackColor` | Property | Gets or sets the background color of the text. |
| `ForeColor` | Property | Gets or sets the color of the text. |
| `FontName` | Property | Gets or sets the font of the text. |
| `FontSize` | Property | Gets or sets the size of the font. |
| `Text` | Property | Returns the text shown - number and unit, or what the user is typing. |
| `ColorScheme` | Property | Gets or sets the color scheme the control draws in. |
| Event | Summary |
|---|---|
| `Change` | Occurs when the user changed the value, after the change was reported to Access. |
| `InvalidEntry` | Occurs when the user left the field with a text that is no number or lies outside the limits; the field shows the value it had when the user entered it again. |
Code example
' Once, in design view: the lifetime of a self-issued key in days.
With Forms!frmKey!spnDays
.ControlSource = "LaufzeitTage"
.Object.MinValue = 1
.Object.MaxValue = 3650
.Object.Step = 30
.Object.Unit = "Tage"
End With
' Form module: tell the user why an entry was refused.
Private Sub spnDays_InvalidEntry(ByVal Text As String, ByVal Message As String)
Me!lblHint.Caption = Message
End Sub
Inheritance
None
Value property
Signature
Property Get Value() As Variant Property Let Value(RHS As Variant)
Summary
Gets or sets the value: the number, or Null for an empty field.
Parameters
None
Property value: Variant – A Long when DecimalPlaces is 0 and the number is whole, else a Double; Null for an empty field. Access writes the field of ControlSource into it on every record change; code may set it. Neither marks the record as changed. A value that is no number raises wkeInvalidValue.
Remarks
A value set by code or by Access is shown as it is, also outside the limits: the limits check what the user enters, as the validation rule of an Access field does not check data that is already stored.
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
Caption property
Signature
Property Get Caption() As String Property Let Caption(RHS As String)
Summary
Gets or sets the name screen readers hear for the field.
Parameters
None
Property value: String – The name; empty (default) uses the control's name.
Remarks
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
MinValue property
Signature
Property Get MinValue() As Variant Property Let MinValue(RHS As Variant)
Summary
Gets or sets the smallest value the user can enter.
Parameters
None
Property value: Variant – A number, or Null (default) for no lower limit. A limit above MaxValue raises wkeInvalidValue.
Remarks
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
MaxValue property
Signature
Property Get MaxValue() As Variant Property Let MaxValue(RHS As Variant)
Summary
Gets or sets the largest value the user can enter.
Parameters
None
Property value: Variant – A number, or Null (default) for no upper limit. A limit below MinValue raises wkeInvalidValue.
Remarks
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
Step property
Signature
Property Get Step() As Double Property Let Step(RHS As Double)
Summary
Gets or sets the change of one press of an arrow or Up/Down.
Parameters
None
Property value: Double – A number greater than 0; default 1. Another number raises wkeInvalidValue.
Remarks
A value off the step grid moves to the next grid value in the direction of the press (2.5 with step 1 goes up to 3 and down to 2); the grid starts at MinValue, else at 0. From an empty field the first press shows the start value: MinValue when it is above 0, else 0.
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
DecimalPlaces property
Signature
Property Get DecimalPlaces() As Long Property Let DecimalPlaces(RHS As Long)
Summary
Gets or sets the decimal places a value is rounded to and shown with.
Parameters
None
Property value: Long – 0 (default) to 10. Another number raises wkeInvalidValue.
Remarks
Values are rounded half away from zero (0.25 with one decimal place is 0.3). The number is shown in the user's regional format without thousands separator; one the user types is accepted.
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
Unit property
Signature
Property Get Unit() As String Property Let Unit(RHS As String)
Summary
Gets or sets the unit shown after the number.
Parameters
None
Property value: String – A text, for example „Tage“; empty (default) for none.
Remarks
Display only: the field keeps the number in that unit. The user may type the number with or without the unit.
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
BackColor property
Signature
Property Get BackColor() As OLE_COLOR Property Let BackColor(RHS As OLE_COLOR)
Summary
Gets or sets the background color of the text.
Parameters
None
Property value: OLE_COLOR – An OLE color; default the window background of Windows.
Remarks
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
ForeColor property
Signature
Property Get ForeColor() As OLE_COLOR Property Let ForeColor(RHS As OLE_COLOR)
Summary
Gets or sets the color of the text.
Parameters
None
Property value: OLE_COLOR – An OLE color; default the window text of Windows.
Remarks
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
FontName property
Signature
Property Get FontName() As String Property Let FontName(RHS As String)
Summary
Gets or sets the font of the text.
Parameters
None
Property value: String – The font name; default Segoe UI. An empty name raises wkeInvalidValue.
Remarks
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
FontSize property
Signature
Property Get FontSize() As Long Property Let FontSize(RHS As Long)
Summary
Gets or sets the size of the font.
Parameters
None
Property value: Long – Points, 6 to 72; default 9. Another size raises wkeInvalidValue.
Remarks
Read/write.
Code example
None
Inheritance
Declared by WklSpinEdit.
Text property
Signature
Property Get Text() As String
Summary
Returns the text shown - number and unit, or what the user is typing.
Parameters
None
Property value: String – The text; an empty text for Null.
Remarks
Read-only.
Code example
None
Inheritance
Declared by WklSpinEdit.
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 frame and the arrow buttons; 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 WklSpinEdit.
Change event
Signature
Event Change()
Summary
Occurs when the user changed the value, after the change was reported to Access.
Parameters
None
Remarks
Occurs for an arrow, a key, the mouse wheel and every typed text that is a valid number - not for a value set by code or by Access. While the user types „4000“ into a field with MaxValue = 3650, the valid steps 4, 40 and 400 each raise Change; leaving the field then brings back the value from entering it and raises Change once more.
In a form module: Private Sub <ControlName>_Change(...). Parameters passed by reference can be changed by the procedure.
Code example
None
Inheritance
Declared by WklSpinEdit.
InvalidEntry event
Signature
Event InvalidEntry(ByVal Text As String, ByVal Message As String)
Summary
Occurs when the user left the field with a text that is no number or lies outside the limits; the field shows the value it had when the user entered it again.
Parameters
| Name | Type | Optional | Default | Description |
|---|---|---|---|---|
Text | String | No | – | What the user had typed. |
Message | String | No | – | Why it was refused, for example „Der Wert muss zwischen 1 und 3650 liegen.“ |
Remarks
In a form module: Private Sub <ControlName>_InvalidEntry(ByVal Text As String, ByVal Message As String). The control shows no message box: show Message where it suits the form, for example in a label beside the field.
In a form module: Private Sub <ControlName>_InvalidEntry(...). Parameters passed by reference can be changed by the procedure.
Code example
None
Inheritance
Declared by WklSpinEdit.