How to lock field after entering value to the field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a form which has two fields that need to be filled up. The first one
is the Math score (1-100 range) and a checkbox field named HasMajor. If the
student has a major this check box is checked. Now I need to come up with a
functionality that will lock fields (both the fields) after entering the
values of the two fields. This means the data entry person will have one
chance to enter the values correctly.

My first question is which event I need to code this - is it after update of
onchagne event. In any event the logic will be:
If form.field1.enabled then
form.field1.disabled
End if.
I would appreciate any help on this?
 
You might also want the following in the onCurrent event:

If Me.NewRecord Or IsNull(Me!field1.Value) then
Me.field1.Locked = False
End If

You will notice that enabled/disabled and Locked affect the control
independent of the content of the data bound to the control.
 
Thanks Steve for your help. I appreciate it. Now in the present case I need
to make sure that when a form is loaded if a box is checked then it should
be locked. I have the following code to do that:
If Me.field1.value = checked then
me.field1.locked = true
else
me.field1.locked = false
end if

The above is being put on the form load and the field gotfocus event.
However, this is not locking the field. Any help is appreciated. Thanks.
 
Well you could use conditional formating. This can enable/disable the
control but you can't change the lock property. In design mode, set the
focus (click) on a control. Then at or near the top of the Format menu list
click on "Conditional Formating". You can use "expression is" to test for
"Me.NewRecord Or IsNull(Me!field1.Value)" and if true disable the control.
On a continuous form this is the only way to avoid locking or disabling a
control in all instances showing on the form.

The onLoad event occurs once when the form is first loaded. The onGotFocus
event happens only when the user tabs or clicks into the control. The
onCurrent event happens when the user moves focus from one record to another
so it is the better place to put the kind of tests you are asking about. But
the caviate about continuous verses single form will be the deciding issue.
 
Back
Top