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

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.
 
K

Ken Snell \(MVP\)

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.
 
D

Doyman

The table that the form is based on has this control set to be indexed with
no duplicates.
 
K

Ken Snell \(MVP\)

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>
 
K

Ken Snell \(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)
 

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