Enable a field only when adding a record

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

Ken Snell [MVP]

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

Jeanette Cunningham

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
 

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