VBA Code for Specific Lookup Selected

RSS705

Registered User.
Local time
Today, 15:28
Joined
Jul 11, 2013
Messages
29
Hi everyone,

What I need:
An if statement which will disable out a field depending on which type of field is selected from a separate lookup.

I know that is confusing, so let me explain with an example. If I have a lookup field connected to "Vegetables", "Fruits" and "Nuts". If the user selects a "Vegetable" from the lookup field, I need another field disabled, for example sake, "What fruit did you buy?". If the user selected a "Fruit" from the lookup, "What fruit did you buy?" would be enabled.

I know how to enable and disable fields, but it is the If Statement that I have no idea about. How would you specify an If statement to specifically look at which category of a lookup is selected?

One last note: The lookup is not static. So going with our example, the user can add more fruits, vegetables, and nuts as desired, so simply specifying the IDs for the available options will not work. The If statement needs to encompass the category.

Thanks for your help in advance,
Rob
 
Does your combobox also contain a column for the category? Assuming the category is the second column.

Code:
If Me.Combo1.column(1) = "Vegetable" Then
'disable fruit and nuts
ElseIf Me.Combo1.column(1) = "Fruit" Then
disable vegetable and nuts
ElseIf Me.Combo1.column(1) = "Nut" Then
'disable vegetable and fruit
'etc. for any other category
End If
 
And this code would need to be in the AfterUpdate event of the Combobox and in the Form_Current event.

Linq ;0)>
 
And must add code to (re)enable the necessary controls.
 
Of course! And for something like this I'd probably use the Select Case construct rather than If...ElseIf...EndIF

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom