Solved Disable a bound textbox on condition in a multiple item form (1 Viewer)

Sipozove

New member
Local time
Today, 22:59
Joined
Mar 23, 2022
Messages
9
Hey,

I would like to disable a bound textbox in a multiple item form, based on another textbox/field value from the same record.
I want to prevent users from entering data in a field/textbox if another field/textbox contains a specific string.
The multiple item form is created from a SELECT view.

So if fieldA/textboxA contains "AAA", textboxB should be disabled (not editable).
If fieldA/textboxA contains anything else, textboxB should be enabled (editable).

I tried this but nothing happens:

Code:
Private Sub Form_Activate()
    If [fieldA] = "AAA" Then
        [fieldB].Locked = True
        [fieldB].Enabled = False
    End If
End Sub

Private Sub Form_Load()
    If [fieldA] = "AAA" Then
        [fieldB].Locked = True
        [fieldB].Enabled = False
    End If
End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:59
Joined
May 21, 2018
Messages
6,450
You can disable and enable individual controls using conditional format. Code will not work since it impacts each.
If you want to do this in code the code goes in the current event, but you have to turn it on and off.

FieldB.enabled = not (fieldA = "AAA")
FieldB.locked = (fieldA = "AAA")

.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:59
Joined
May 7, 2009
Messages
16,881
use Conditional format to Enable/disable the control.
 

Sipozove

New member
Local time
Today, 22:59
Joined
Mar 23, 2022
Messages
9
Ok, that was fast, simple and solid!
Didn't see the expression option :p

Thank you very much.
 

Users who are viewing this thread

Top Bottom