if user selects wrong value, display message

megatronixs

Registered User.
Local time
Today, 21:18
Joined
Aug 17, 2012
Messages
719
Hi all,

I have a field that is pre filled in with a value. The name is "Business"
Then there is a combo box with various values. If the user would select a value that does not match with values that can be selected if in "business" a value is selected, it should show a message that the selection is wrong and user needs to select the correct one.

Example:
If in the field "Business" the value "Food" is selected, then the possible values to be selected in the combobox would be: Fruit or Meet or Fast Food. If the value in "Business" would be "Wood" only selections could be made: Talble or Chair or Cabinet.
So, if a user select "Food' in "Business" and in the combo box "Chair", it should show a message that the wrong selection was made and don't let them use the wrong one.

Any help in getting this solving this?

Greetings.
 
Is this combo in a table field or on a form?

If a form, then you can set the combobox's LimitToList property to Yes and, in the OnNotInList event, the following:

Code:
Response = acDataErrContinue
 
Hi,
The combobox is in a form (the same as the field "Business")
 
Well, it won't show a message to the user, but it will restrict their choice to the options in the combobox.

If you want to do a message, then these lines:

Code:
Private Sub YourComboBox_NotInList((NewData As String, Response As Integer)
    MsgBox "The selection is wrong.", vbExclamation + vbOkOnly, "Wrong Selection"
    Response = acDataErrContinue
End Sub

Do make sure that your combo's LimitToList property is set to Yes.
 
Actually, just reading your example, which is a little different from what I inferred from the start (That should teach me to read the whole thread!)

What you're after is Cascading Comboboxes. There's are thousands of examples of these on the forum, if you do a search.
 
Hi,

I think it is a better solution and need to check this out.
Thanks for pointing this one :-)
 
Hi,

One question about this. Can it also be that the values could be in the code istead of a table?
 
It could be, but that would be counter-productive. Ideally you would not want to do the rework on the database each time a new business or whatever, was added. Going by code, you would then have to hard code in the new business each time.

By putting the data in a table - and, after all, it is a database table; that's what they are for - you don't need to worry about hard coding as it's effectively future proofing this element.

Plus, it's not a good practice. Hardcoding in general...and also implementing your own business logic into a form's module.
 
Hi,

Thanks. I will give it a try with the tables and see how it goes :-)

Greetings.
 

Users who are viewing this thread

Back
Top Bottom