Short Validation rule for a Combo box (1 Viewer)

beckie1234

Struggling Student
Local time
Yesterday, 21:26
Joined
Mar 10, 2007
Messages
94
I have a form that has a combo box labeled 'line' and I have a combo box labeled
'MachineCenter'. I want to create a validation rule so that if a user picks 'Line 2' in the first combobox they can't enter 'backline' in the second combo box. I am not sure how to write it.
Can anyone help with this one??
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 05:26
Joined
Sep 12, 2006
Messages
15,696
in the second combo box, in the before update event you can have

if combo2= backline and combo 1 = line 2 then
call msgbox("sorry - that value not allowed")
cancel = vbcancel 'most important - prevents the entry being accepted
exit sub


however - what if they've selected backline in combo2 BEFORE they pick one from combo1 ......

it can get tricky, which is why so much of any code is to prevent errors etc, not just to do the processing
 

beckie1234

Struggling Student
Local time
Yesterday, 21:26
Joined
Mar 10, 2007
Messages
94
If MachineCenter = backline And Line = "Line 2" Then
Call MsgBox("sorry - that value not allowed")
Cancel = vbCancel
End If

This is exactly what I put in and it still allows the user to enter Backline on Line 2. Did I miss something? No error message or anything else pops up.
MachineCenter is the name of the second combo box and Line is the name of the first combo box.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 05:26
Joined
Sep 12, 2006
Messages
15,696
if the combo boxes are using a hidden id column (which is usual), then the value of the combo box is NOT eg backline, but rather the id in the lookup table that relates to backline

is that causing the problem?
 

beckie1234

Struggling Student
Local time
Yesterday, 21:26
Joined
Mar 10, 2007
Messages
94
Yes that was the problem Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!
 

Users who are viewing this thread

Top Bottom