You'll first have to move focus to another control, then you can set the
Locked and Enabled properties of the control so that the user cannot edit it.
Put code along these lines in the control's AfterUpdate event procedure:
Me.SomeOtherControl.SetFocus
Me.YourComboBox.Locked = True
Me.YourComboBox.Enabled = False
Setting both the Locked and Enabled properties in this way makes the control
unavailable to the user while keeping its normal appearance, rather than
greying it out as would be the case if you only set the Enabled property to
False.
To make the control available when the user navigates to a record where the
control is Null, or to a new record, put code in the form's Current event
procedure:
Me.SomeOtherControl.SetFocus
Me.YourComboBox.Locked = Not IsNull(Me.YourComboBox)
Me.YourComboBox.Enabled = IsNull(Me.YourComboBox)
The other control to which you move focus in this case need not be the same
one as in the first case, so in the form's Current event procedure you'd
probably move focus to the first control on the form, while in the control's
AfterUpdate event procedure you'd move focus to the next control after the
combo box in the tab order. If the first control on the form is the combo
box in question, however, you'd have to first move focus to another control
on the form as you can't set these properties while the combo box has focus;
you can then move focus back to the combo box if it is available. If its not
available an error will be raised, so you'd handle this by adding extra lines
of code along these lines to the above code in the form's Current event
procedure:
On Error Resume Next
Me.YourComboBox.SetFocus
Ken Sheridan
Stafford, England