Rolliee:
Locking the field code prohibits changes to the field from the keyboard, but pressing the command button triggers the vba code which does change the contents.
I think the vb code needs an if string...
If Me.tblTestID =0 or "", then enter number, If not MsgBox "This record cannot accept a new ID."
I Locked the field and applied the following code which does not work. I get no message box and, pressing the command button keeps changing the ID.
Private Sub CreateTestID_Click()
'MsgBox Str(Rnd()) * (10000000)
'me.IDField = int(rnd()*1000000
If (Me.tblTestID = 0) Or (Me.tblTestID = ""

Then
MsgBox ("Record ID already exists"

Else
Me.tblTestID = Int(Rnd() * 1000000)
End If
End Sub
Robert