How to unlock fields on form to add

F

Flick Olmsford

Access 2003 - Windows XP SP2

Users are supposed to use a combo box at the top of a form I created to
search for a person's name. Sometimes they do not do this.

In order to stop people from accidently wiping out certain info on a form
when searching therefore (in addition to training), I want to set the last
and first name fields to ENABLED = NO, LOCKED=YES and shade the field to
another background color. I want to unlock and enable the fields for data
entry though.

I set the fields on the control properties accordingly. In the BEFORE
INSERT event on the form, I added code to set the background color to white,
ENABLED to YES, and LOCKED to NO. I also set the .setfocus to the last name
field where I want it. Same code for three fields.

When I add this code, and test it by hitting the add record navigation
button, the fields background colors do not change, the setfocus event goes
to the wrong field and one in a subform, and the fields are still locked.
It is in add mode though.

Should I not use the form's before insert event? How do I get the fields
to properly unlock, reshade, and set focus during add?
 
K

Klatuu

If you want to unlock the controls only if the user has used the combo box to
search, do it in the After Update event of the combo. Just set the enabled
and locked properties of the control. You will need to relock them in the
form's Current event If it is a new record.
 
F

Flick Olmsford

Actually, I did not envision that. They would use the combo box for records
already in the table. If they did that and knew the person was new, they
should use the New Record navigation button.

What event do I use for that? Does the new record navigation button not
work with events? I can add a command button if that is best but I prefer
not to.
 
K

Klatuu

The only events that will fire with the navigation buttons are any that are
attached to the current record, like before update, after update, etc.
Then you will fire the Current event for the form.
If it is a new record, the combo has a Not In List event you can use if the
value entered is not in the combo's row source.
This event is commonly used to ask the user if they want to add the new
record and add the record or not depending on the user's selection.
 
F

Flick Olmsford

I was not aware this, nor of the not in list event. Thanks. I'll try the
different options.
 

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