Barvna shema: Temna
Trenutno dejavna stran: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library how-to guides » How to: Look up a value with a button beside the text

How to: Look up a value with a button beside the text

Use WklButtonEdit, bound to a field on the form, to let users either type a value or fetch it with a button: look up a Windows account in a search dialog, test a connection string, or replace a secret.

Requires WKL Forms Object Library 1.43 or later.

Solution overview

  • Bind it like a text box: Control Source (ControlSource) names the field.
  • The button raises ButtonClick. Your procedure opens the dialog and writes the result both to the field (the record becomes dirty and is saved like any other edit) and to Value (so the control shows it immediately).
  • Read-only text for secrets: set TextEditable = False and PasswordMask = True, and label the button „Change…“. PasswordMask only hides what's displayed: the value is still plain text in the bound field and in Value.

Implementation

A form frmIdentity is bound to tblIdentity and contains a WklButtonEdit btnAccount bound to the field Account:

' Once, in design view (or on the designer's Button page); saved with the form.
With Forms!frmIdentity!btnAccount
    .ControlSource = "Account"
    .Object.ButtonText = "Find account"
    .Object.Caption = "Windows account"
End With
' Module of frmIdentity: the button fetches the account.
Private Sub btnAccount_ButtonClick()
    Dim account As String
    account = InputBox("Windows account (DOMAIN\Name):", "Find account", Nz(Me!Account, ""))
    If Len(account) = 0 Then Exit Sub
    Me!Account = account                     ' the field: the record is now changed (dirty)
    Me!btnAccount.Object.Value = account     ' the control: shows it at once
End Sub

A secret that only your own dialog can replace:

With Forms!frmIdentity!btnSecret.Object
    .TextEditable = False
    .PasswordMask = True
    .ButtonCaption = "Change…"
    .ButtonText = "Change secret"
End With

Remarks

  • While the user is typing, read the control. The control reports every change to Access, which copies it to the field when the record is saved; until then, Me!Account may still hold the previous value (just as with a bound WklToggleSwitch).
  • Locked and AllowEdits. A locked control (Locked) or a form with AllowEdits = False rejects typing, but the button still raises ButtonClick. If your dialog would change the record, check Me.AllowEdits in the procedure.
  • Esc restores the value from before the user's first change; a second Esc goes to Access and undoes the record.
  • Not in the detail section of a continuous form: Access creates only one instance of the control there; in a list, use a WklGrid column instead.
en/wiki/msaccess/comctl/how-to/look-up-a-value-with-a-button.txt · Zadnja sprememba: uporabnika Wolfgang van der Stille