Lock a text field after an update

  • Thread starter Thread starter guaj1818
  • Start date Start date
G

guaj1818

Hi,

I am using Microsoft Access 2000 and I have two text fields in my form
called NetID and CustomerID. Is there a way to have the fields locked
after the user enters a netid and customerid for the first time after
a new post is created? I don't want the user to be able to modify or
delete any of the text fields after the first input.

Any help would be highly appreciated. Thanks in advance.
 
to prevent changes to a control with data already in it, try adding an event
procedure to the control's OnEnter event, as

Private Sub MyControlName_Enter()

Screen.ActiveControl.Locked = Not IsNull(Screen.ActiveControl)

End Sub

one point to consider: if the user enters a value in the control, moves out
of the control, and then realizes he/she made an error in the entry - it's
too late. the control will be locked when the user goes back to it,
preventing any correction of data.
there are ways to lock a record, or specific field(s) *after* all the data
has been entered once and the record saved, so that the next time the record
is reviewed in the form, it can't be modified. if that's what you need
instead, post back to this thread.

hth
 
Hi,

I added the event that you suggested but it doesn't seem to have any
effect on the form. I am still able to modify the NetID text field in
my form.
I just copied the procedure and modified my control name to NetID.
Also, this event that I add doesn't show on the list of all events
when I right-click on the text-field control of NetID and look at the
properties.
-----------------------------------------
Private Sub NetID_Enter()

Screen.ActiveControl.Locked = Not IsNull(Screen.ActiveControl)

End Sub
-----------------------------------------
Perhaps I have done something wrong?

But the other way of locking a record that you wrote about also sounds
interesting. How can I use that method in my form?

By the way, I am using MS Access 2002.

Thanks.
 
hmmm, i tested the code before posting, so i know it does work. i think you
did add it incorrectly, but i'm trying to figure out how.
Also, this event that I add doesn't show on the list of all events
when I right-click on the text-field control of NetID and look at the
properties.

that seems impossible. this is a text box on a form? and you opened the form
in design view? right clicked the control, selected Properties, and looked
at the Events tab? and there is no On Enter event listed?
if you added the procedure to the form's module, correcting the name of the
procedure to match your control name, then in the Properties box for that
control you should see the On Enter line with
[Event Procedure]
if you see the On Enter line, but it's empty, then click on it. click the
"down arrow" and select Event Procedure. then click the Build button (...)
at the right and you will go directly to that procedure in the form module.
post back with results. we need to understand what's going on here before we
tackle another process.
 
Hi,

Thanks very much for your reply. I added the same event procedure
again in my file and now it is working! Now I can also see the event
in the properties box for my netid text field.
But now there is that problem you mentioned in your previous reply
that if one happens to type the netid incorrectly and press enter the
text-field gets locked.
You mentioned that there was an other way to lock a record after all
the data had been entered and the record saved. How does that work?
The first method is working now, but if I can use the other way it
would be even better as users often make errors when entering data.

Thanks once again.


tina said:
hmmm, i tested the code before posting, so i know it does work. i think you
did add it incorrectly, but i'm trying to figure out how.
Also, this event that I add doesn't show on the list of all events
when I right-click on the text-field control of NetID and look at the
properties.

that seems impossible. this is a text box on a form? and you opened the form
in design view? right clicked the control, selected Properties, and looked
at the Events tab? and there is no On Enter event listed?
if you added the procedure to the form's module, correcting the name of the
procedure to match your control name, then in the Properties box for that
control you should see the On Enter line with
[Event Procedure]
if you see the On Enter line, but it's empty, then click on it. click the
"down arrow" and select Event Procedure. then click the Build button (...)
at the right and you will go directly to that procedure in the form module.
post back with results. we need to understand what's going on here before we
tackle another process.


guaj1818 said:
Hi,

I added the event that you suggested but it doesn't seem to have any
effect on the form. I am still able to modify the NetID text field in
my form.
I just copied the procedure and modified my control name to NetID.
Also, this event that I add doesn't show on the list of all events
when I right-click on the text-field control of NetID and look at the
properties.
-----------------------------------------
Private Sub NetID_Enter()

Screen.ActiveControl.Locked = Not IsNull(Screen.ActiveControl)

End Sub
-----------------------------------------
Perhaps I have done something wrong?

But the other way of locking a record that you wrote about also sounds
interesting. How can I use that method in my form?

By the way, I am using MS Access 2002.

Thanks.


"tina" <[email protected]> wrote in message
 
in the form's OnCurrent event, add a procedure (as i described in my
previous post) and add the following code:

Me!MyControlName.Locked = Not IsNull(Me!MyControlName)
(notice that you have to use a specific control name in this line of code)

the Current event fires when you first open the form, because the focus
settles on a single record, and fires again each time you move from one
record to another. so you can lock/unlock any number of controls for the
appropriate conditions of each record.
if you want to lock control(s) in the current record after data entry is
completed, *without* moving to another record, then add the same code to the
form's AfterUpdate event *in addition to* the OnCurrent event.

if you want to lock the entire record, rather than just certain controls,
then try using the following code instead, as

Private Sub Form_Current()

Me.AllowEdits = IsNull(Me!MyControlName)

End Sub
(use a control that should always have a value in a saved record, such as
the primary key field)

AllowEdits is a form property. if you use this solution, suggest you read up
on it in Access Help. suggest you also read up on properties AllowAdditions,
AllowDeletions and DataEntry - so you can tailor the form's behavior to suit
your needs.

hth


guaj1818 said:
Hi,

Thanks very much for your reply. I added the same event procedure
again in my file and now it is working! Now I can also see the event
in the properties box for my netid text field.
But now there is that problem you mentioned in your previous reply
that if one happens to type the netid incorrectly and press enter the
text-field gets locked.
You mentioned that there was an other way to lock a record after all
the data had been entered and the record saved. How does that work?
The first method is working now, but if I can use the other way it
would be even better as users often make errors when entering data.

Thanks once again.


tina said:
hmmm, i tested the code before posting, so i know it does work. i think you
did add it incorrectly, but i'm trying to figure out how.
Also, this event that I add doesn't show on the list of all events
when I right-click on the text-field control of NetID and look at the
properties.

that seems impossible. this is a text box on a form? and you opened the form
in design view? right clicked the control, selected Properties, and looked
at the Events tab? and there is no On Enter event listed?
if you added the procedure to the form's module, correcting the name of the
procedure to match your control name, then in the Properties box for that
control you should see the On Enter line with
[Event Procedure]
if you see the On Enter line, but it's empty, then click on it. click the
"down arrow" and select Event Procedure. then click the Build button (...)
at the right and you will go directly to that procedure in the form module.
post back with results. we need to understand what's going on here before we
tackle another process.


guaj1818 said:
Hi,

I added the event that you suggested but it doesn't seem to have any
effect on the form. I am still able to modify the NetID text field in
my form.
I just copied the procedure and modified my control name to NetID.
Also, this event that I add doesn't show on the list of all events
when I right-click on the text-field control of NetID and look at the
properties.
-----------------------------------------
Private Sub NetID_Enter()

Screen.ActiveControl.Locked = Not IsNull(Screen.ActiveControl)

End Sub
-----------------------------------------
Perhaps I have done something wrong?

But the other way of locking a record that you wrote about also sounds
interesting. How can I use that method in my form?

By the way, I am using MS Access 2002.

Thanks.


"tina" <[email protected]> wrote in message
to prevent changes to a control with data already in it, try adding
an
event
procedure to the control's OnEnter event, as

Private Sub MyControlName_Enter()

Screen.ActiveControl.Locked = Not IsNull(Screen.ActiveControl)

End Sub

one point to consider: if the user enters a value in the control,
moves
out
of the control, and then realizes he/she made an error in the
entry -
it's
too late. the control will be locked when the user goes back to it,
preventing any correction of data.
there are ways to lock a record, or specific field(s) *after* all
the
data
has been entered once and the record saved, so that the next time
the
record
is reviewed in the form, it can't be modified. if that's what you need
instead, post back to this thread.

hth


Hi,

I am using Microsoft Access 2000 and I have two text fields in my form
called NetID and CustomerID. Is there a way to have the fields locked
after the user enters a netid and customerid for the first time after
a new post is created? I don't want the user to be able to modify or
delete any of the text fields after the first input.

Any help would be highly appreciated. Thanks in advance.
 
Back
Top