Lock a field

G

Guest

I have a form based on a table that has a field where the user enters their
name from a drop down box. What I would like to do is after the user chooses
his/her name, the field locks out any changes. Is this possible and if so
where do I start?
Any help appreciated.

Joseph
 
M

Marshall Barton

sacredarms said:
I have a form based on a table that has a field where the user enters their
name from a drop down box. What I would like to do is after the user chooses
his/her name, the field locks out any changes. Is this possible and if so
where do I start?


You can use the combo box's AfterUpdate event procedure to
lock the combo box:

Me.comboboxname.Locked = Not IsNull(Me.comboboxname)

You should also have the same line of code in the form's
Current event so it can't be changed when they first
navigate to a different record or reopen the form later.

But, the AfterUpdate event doesn't allow a user to make a
correction if they picked the wrong name. Wouldn't it be
better to only lock it after they have finished with the
record? If so, then only use the form's Current event to
run the line of code.
 
R

Ronald Roberts

In the AfterUpdate event of the Drop Down box you can do:
Me.ControlName.Locked = true
But, what if the user happens to click the wrong name by mistake.
How or what method are you going allow the user to use to unlock
the drop down box.

Ron
 
G

Guest

Thanks for the help but I now get an error that reads "microsoft office
cannot find the macro named me:
 
G

Guest

I understand the question but I am not sure that I want the info allowed to
be changed unless I can track the changes.
 
M

Marshall Barton

It sounds like you put the line of code in the AfterUpdate
event **property**, which should contain
[Event Procedure]

The code belongs in the combo box's AfterUpdate event
**procedure** (in the form's module). You can get to the
procedure by clicking on the [...] button over in the right
edge of the event property.
 
R

Ronald Roberts

When you create the AfterUpdate Event, you should select the expression
builder, not the macro builder.
The Line below is VBA code not a macro

Me.comboboxname.Locked = Not IsNull(Me.comboboxname)

Ron
 
R

Ronald Roberts

You understand your application, I don't. The point is, I can't
think of any reason why I would want to do this. If it is for
security, there are other ways of doing what you want. Maybe
if you would tell us what you want to do, others can help with a
better answer.

Ron
 
G

Guest

Hi again, I was just looking for the person who logged the event. I would
want to lock the field but I guess you're right. If someone does enter the
wrong information I would need them to correct it, so I will leave it as is.
Thanks
Joseph
 
G

Guest

It sounds like you might want to do something like what I frequently use.

In most of my Access apps (which are very simple), I just want to know who
originally put in the record. The easiest way to do this for me is to just
read their network ID, and record this in a field of the original record. I
can link it back to a reference table that has all of their personal info
(phone, mail code, department).

It is easier to grab the names, but you create yourself some work by having
to maintain the personal data table.

There are probably many ways to capture the network ID, but I use the
following in the OnLoad of the new record form:

Private Sub Form_Load()
Dim strenv As String
strenv = UCase$(Environ$("USERNAME"))
Me![Preparer_ID] = strenv
End Sub
 

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