Add record then lock field

M

mewins

This is similar to some other questions that have been answered, but I can’t
quite figure out how to do it. I want to be able to add a new record and
then lock certain fields after the initial creation. Specifically, I want to
add in a new client’s first and last name ([firstname] and [lastname]) in a
new record, and then afterwards, lock those fields from being edited in the
form to prevent staff erasing/changing the names (I would still like to be
able to edit names in the table though). Right now I have a command button
that does the standard add record code and another with the standard refresh,
but I’m guessing I need to add some code to lock those fields in one of those
command buttons. Any ideas? Thanks!
 
M

Mr. B

Try adding the code below to the OnCurrent event of your form:

If not isnull(me.NameOfFirstNameControl) and _
not isnull(me.NameOfLastNameControl) then
Me.NameOfFirstNameControl.locked = true
Me.NameOfLastNameControl.locked = true
else
Me.NameOfFirstNameControl.locked = false
Me.NameOfLastNameControl.locked = false
end if

This code will lock both controls for editing if they are already populated
when the record is presented. If they are not populated then they can be
edited.


-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm
 
C

Chegu Tom

I assume you are using a form to input the data.

You might want to permanently lock the controls for fitst and last name on
the form (so they cannot be edited by the user but can still be changed by
VBA code)

then have a button on your form to create a new record

that procedure would prompt for the first and last names (using inputbox or
a popup form), create a new record, add those names to the record, and then
open the
record for editing. The user can now add/change any controls on the form
except the two you have locked.

Tom
 
R

Rick A.B.

This is similar to some other questions that have been answered, but I can’t
quite figure out how to do it.  I want to be able to add a new record and
then lock certain fields after the initial creation.  Specifically, I want to
add in a new client’s first and last name ([firstname] and [lastname]) in a
new record, and then afterwards, lock those fields from being edited in the
form to prevent staff erasing/changing the names (I would still like to be
able to edit names in the table though).  Right now I have a command button
that does the standard add record code and another with the standard refresh,
but I’m guessing I need to add some code to lock those fields in one ofthose
command buttons.  Any ideas?  Thanks!

Just my two cents but I normally never lock controls for editing but
rather use a validate routine in the before update of the control if
it's not null to have the user verify that they desire to change the
name. It keeps them from accidently changing the contents but gives
them the flexability to change it if needed.

Rick
 
M

mewins

Thanks, I'll try this

Mr. B said:
Try adding the code below to the OnCurrent event of your form:

If not isnull(me.NameOfFirstNameControl) and _
not isnull(me.NameOfLastNameControl) then
Me.NameOfFirstNameControl.locked = true
Me.NameOfLastNameControl.locked = true
else
Me.NameOfFirstNameControl.locked = false
Me.NameOfLastNameControl.locked = false
end if

This code will lock both controls for editing if they are already populated
when the record is presented. If they are not populated then they can be
edited.


-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm


mewins said:
This is similar to some other questions that have been answered, but I can’t
quite figure out how to do it. I want to be able to add a new record and
then lock certain fields after the initial creation. Specifically, I want to
add in a new client’s first and last name ([firstname] and [lastname]) in a
new record, and then afterwards, lock those fields from being edited in the
form to prevent staff erasing/changing the names (I would still like to be
able to edit names in the table though). Right now I have a command button
that does the standard add record code and another with the standard refresh,
but I’m guessing I need to add some code to lock those fields in one of those
command buttons. Any ideas? Thanks!
 
M

mewins

Thanks!

Mr. B said:
Try adding the code below to the OnCurrent event of your form:

If not isnull(me.NameOfFirstNameControl) and _
not isnull(me.NameOfLastNameControl) then
Me.NameOfFirstNameControl.locked = true
Me.NameOfLastNameControl.locked = true
else
Me.NameOfFirstNameControl.locked = false
Me.NameOfLastNameControl.locked = false
end if

This code will lock both controls for editing if they are already populated
when the record is presented. If they are not populated then they can be
edited.


-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm


mewins said:
This is similar to some other questions that have been answered, but I can’t
quite figure out how to do it. I want to be able to add a new record and
then lock certain fields after the initial creation. Specifically, I want to
add in a new client’s first and last name ([firstname] and [lastname]) in a
new record, and then afterwards, lock those fields from being edited in the
form to prevent staff erasing/changing the names (I would still like to be
able to edit names in the table though). Right now I have a command button
that does the standard add record code and another with the standard refresh,
but I’m guessing I need to add some code to lock those fields in one of those
command buttons. Any ideas? Thanks!Th
 

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