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

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
 
J

John W. Vinson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top