Disable data entry field for specific combo box values

loki1049

Registered User.
Local time
Today, 10:58
Joined
Mar 11, 2010
Messages
28
Hi, I'm having trouble creating a form that has a drop down list and two entry fields. Both entry fields have a default value of NULL. Now what I am trying to do is keep the user from entering data in one of the fields when one of the values is selected from the combo box, and have both fields available when the other value is selected in the combo box.

The combo box has a row source as the query of another table, and the two field boxes where data is entered is bound to the table which data is being added to. The form type is set to 'data entry'

A simple example would be I have a table housing Automotive Models, with the types Ford Pinto and Ford Mustang, then the data entry might have things like "Type Fuel Injection Code" and "Type Engine Code", but the Pinto is not fuel injected so I don't want the user to be able to see that entry box.
 
You could use something along the lines of;
Code:
If Me.Combo = [B][COLOR="Magenta"]Condition to lock field[/COLOR][/B] Then
     Me.TextBox1.Enabled = False
     Me.TextBox1.Locked = True
     Me.TextBox2.Enabled = True
     Me.TextBox2.Locked = False
Else
     Me.TextBox1.Enabled = True
     Me.TextBox1.Locked = False
     Me.TextBox2.Enabled = True
     Me.TextBox2.Locked = False
End If

You will need to put this code in the On Current Event of the Form and also in the On Change Event of the Combo.

Change Condition to lock field to the result in the combo you wish to test for.
 
Thanks, exactly what I was looking for!
 

Users who are viewing this thread

Back
Top Bottom