Color scheme: Dark
You are here: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » Status and feedback » WklStatusLabel » Show the state of a service

Show the state of a service

In this tutorial, you show the state of each service in a table as a colored label that follows the current record: “Running” in green, “Stopped” in gray, and “Down” in red.

Prerequisites

  • Microsoft 365 Access or the Access Runtime, 32-bit or 64-bit, with the WKL Forms Object Library 1.23 or later installed and registered for the current Windows user (How to: Install the released package).
  • A new or existing database in a trusted location.
  • Every WKL control opens its designer the same way: in Design view, in the property sheet (F4), on the Other tab, in the Custom row, [...] (Opening the designer).

Steps

1. Create the sample table

Paste the procedure into a standard module and run it once from the Immediate window (CreateStatusSample):

Public Sub CreateStatusSample()
    With CurrentDb
        .Execute "CREATE TABLE tblServices (ID LONG CONSTRAINT PK_Services PRIMARY KEY, ServiceName TEXT(50), State TEXT(30))"
        .Execute "INSERT INTO tblServices VALUES (1, 'Sync', 'running')"
        .Execute "INSERT INTO tblServices VALUES (2, 'Warehouse', 'stopped')"
        .Execute "INSERT INTO tblServices VALUES (3, 'Shipping', 'failed')"
        .Execute "INSERT INTO tblServices VALUES (4, 'Archive', Null)"
    End With
End Sub

2. Create the form and insert the label

Create a single form frmServices bound to tblServices with a text box ServiceName. Choose Form Design › Controls › ActiveX Controls › WKL Status Label, draw it below the text box about 6 cm wide and 0.5 cm high, and name it lblState. Set its Control Source (property sheet, Data tab) to State.

3. Add the entries

The entries define which text, kind, and symbol each value gets. They're stored with the form, so add them once in Design view: paste the procedure into a standard module, run it while frmServices is open in Design view, and then save the form.

Public Sub SetStatusEntries()
    With Forms!frmServices!lblState.Object
        .Caption = "State"
        .NullText = "unknown"
        .ClearStatusItems
        .AddStatusItem "running", "Running", wskOk, "E768"
        .AddStatusItem "stopped", "Stopped", wskNeutral
        .AddStatusItem "failed", "Down", wskBad, "E783"
    End With
End Sub

4. Try it

Open the form in Form view and move through the records: “State: Running” in green with a play symbol, “Stopped” in gray, “Down” in red, and “unknown” for the record without a state.

Expected result

  • The label follows the current record and never makes it dirty.
  • A value without an entry (for example, “paused”) appears as text in the designed kind.
  • A screen reader announces “State: Running” and the kind.

Next steps

en/wiki/msaccess/comctl/status-and-feedback/statuslabel/tutorial.txt · Last modified: by Wolfgang van der Stille