I want to inhibit editing of one text box based on the value of another

  • Thread starter Thread starter BobC
  • Start date Start date
B

BobC

The two text boxes are on the same form (subform3).
I want to inhibit the Quantity filed from being edited if the Status
field contains "Ship Requested".

The following code gives me an error 'Expected: list separator or )'
Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IIf(me.Status = "Ship Requested"; me.AllowEdits = True, _
me.AllowEdits = False)
End Sub
 
The two text boxes are on the same form (subform3).
I want to inhibit the Quantity filed from being edited if the Status
field contains "Ship Requested".

The following code gives me an error 'Expected: list separator or )'
Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IIf(me.Status = "Ship Requested"; me.AllowEdits = True, _
me.AllowEdits = False)
End Sub

Use the AfterUpdate event instead; and use an IF block rather than calling the
builtin IIf() function. You'll also want to enable or disable the textbox
rather than changing the entire form's AllowEdits property, which would stop
you from editing any other field on the form.

Private Sub Quantity_BeforeUpdate(Cancel As Integer)
' Inhibit txtbox if the Status field is "Ship Requested"
IF me.Status = "Ship Requested" Then
me.Quantity.Enabled = False
Else
me.Quantity.Enabled = True
End If
End Sub

You'll also want to put the same code in the Form's Current event.
 
Back
Top