Enable a field only when adding a record

  • Thread starter Thread starter So Call Me Crazy
  • Start date Start date
S

So Call Me Crazy

I want to enable the field that is the primary key ONLY when a new record is
being added. Otherwise, I want to disable the field so the primary key
cannot be changed by a user.

I cannot seem to figure this out.

TIA,
 
Use the form's Current event to do this:

Private Sub Form_Current()
Me.SomeOtherControlOnTheForm.SetFocus
Me.PrimaryKeyControlName.Enabled = (Me.NewRecord = True)
End Sub

Be sure that this control does not potentially have the initial focus, else
you won't be able to disable it.
 
Hi So Call Me Crazy,
as you have found, letting users see the primary key just makes your life
more difficult.
Nearly all developers hide the primary key from the user. To hide it, set
its visible property to No on its property dialog.
The users won't be able to change it when it is hidden.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Back
Top