Is there a way to make a field read-only after it has been written

  • Thread starter Thread starter Doyman
  • Start date Start date
D

Doyman

In access 2003, I have a form that multiple users access. I need to make a
certain field read only after the user has entered a unique number. Can
someone help me figure out how to do this?
Thanks in advance.
 
By "field", may we assume that you mean a control (e.g., textbox) on a form?
If yes, you can lock the control after the user enters the unique data.
 
The table that the form is based on has this control set to be indexed with
no duplicates.
 
Easiest way to do this is to use BeforeUpdate event of the control to run
some simple VBA code:

Private Sub NameOfControlBoundToField_BeforeUpdate(Cancel As Integer)
If DCount("*", "NameOfTable", "NameOfField=" &
Me.NameOfControlBoundToField.Value) _
MsgBox "Cannot enter a duplicate value!"
Cancel = True
End If
End Sub
--

Ken Snell
<MS ACCESS MVP>
 
Sorry - my suggestion isn't quite the solution that you're seeking.

You can lock a control based on the value in the control, using the form's
Current event:

Private Sub Form_Current()
Me.NameOfControlBoundToField.Locked = ( _
DCount("*", "NameOfTable", "NameOfField=" & _
Me.NameOfControlBoundToField.Value) >0)
End Sub

This can be done by a macro instead of VBA programming:

Action: SetValue
Item: NameOfControlBoundToField.Locked
Expression: DCount("*", "NameOfTable", "NameOfField=" &
NameOfControlBoundToField.Value) > 0)
 
Back
Top