Question : VBA if formula bringing up wrong results.

Hi EE
I have written VBA that I have put in the 'After Update' Event
I have a form that has 10 dropdown boxs. when you select a value in in combo box the vba copies the value to an adjacent field.
when you go to the next combo box and enter a value the same hapens but also looks up to see if this value exists anywhere else and if so deletes the value and pops up a message box.

PROBLEM:
I cant work out why but the first 2 work fine but from the 3rd combo box onwards (ten in all) it pops up the message box even tho the value you enter is NOT anywhere else.

So in combo box 1 i have a value of 1
in combo box 2 a value of 16
when you put a value of 17 in ANY other combo boxs it still brings up message box.

I understand that a combo box sometimes displays a name however it records a number or what ever is in its bound column, i have checked and all bound columns are the same.....
All fields in this form are unbound.
I am using access 2003
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
Private Sub cboEmployee1_AfterUpdate()

Me.StaffValue1 = Me.cboEmployee1


If Me.cboEmployee1 = Me.StaffValue2 Or Me.StaffValue3 Or Me.StaffValue4 Or Me.StaffValue5 Or Me.StaffValue6 Or Me.StaffValue7 Or Me.StaffValue8 Or Me.StaffValue9 Or Me.StaffValue10 Then
Me.StaffValue1 = Null
Me.cboEmployee1 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee1.SetFocus
      Exit Sub
   End If
End Sub
Private Sub cboEmployee2_AfterUpdate()

Me.StaffValue2 = Me.cboEmployee2

If Me.cboEmployee2 = Me.StaffValue1 Or Me.StaffValue3 Or Me.StaffValue4 Or Me.StaffValue5 Or Me.StaffValue6 Or Me.StaffValue7 Or Me.StaffValue8 Or Me.StaffValue9 Or Me.StaffValue10 Then
Me.StaffValue2 = Null
Me.cboEmployee2 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee2.SetFocus
      Exit Sub
   End If
End Sub
Private Sub cboEmployee3_AfterUpdate()

Me.StaffValue3 = Me.cboEmployee3

If Me.cboEmployee3 = Me.StaffValue1 Or Me.StaffValue2 Or Me.StaffValue4 Or Me.StaffValue5 Or Me.StaffValue6 Or Me.StaffValue7 Or Me.StaffValue8 Or Me.StaffValue9 Or Me.StaffValue10 Then
Me.StaffValue3 = Null
Me.cboEmployee3 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee3.SetFocus
      Exit Sub
   End If
   
End Sub
Private Sub cboEmployee4_AfterUpdate()

Me.StaffValue4 = Me.cboEmployee4

If Me.cboEmployee4 = Me.StaffValue1 Or Me.StaffValue2 Or Me.StaffValue3 Or Me.StaffValue5 Or Me.StaffValue6 Or Me.StaffValue7 Or Me.StaffValue8 Or Me.StaffValue9 Or Me.StaffValue10 Then
Me.StaffValue4 = Null
Me.cboEmployee4 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee4.SetFocus
      Exit Sub
   End If
End Sub
Private Sub cboEmployee5_AfterUpdate()

Me.StaffValue5 = Me.cboEmployee5

If Me.cboEmployee5 = Me.StaffValue1 Or Me.StaffValue2 Or Me.StaffValue3 Or Me.StaffValue4 Or Me.StaffValue6 Or Me.StaffValue7 Or Me.StaffValue8 Or Me.StaffValue9 Or Me.StaffValue10 Then
Me.StaffValue5 = Null
Me.cboEmployee5 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee5.SetFocus
      Exit Sub
   End If
End Sub
Private Sub cboEmployee6_AfterUpdate()

Me.StaffValue6 = Me.cboEmployee6

If Me.cboEmployee6 = Me.StaffValue1 Or Me.StaffValue2 Or Me.StaffValue3 Or Me.StaffValue4 Or Me.StaffValue5 Or Me.StaffValue7 Or Me.StaffValue8 Or Me.StaffValue9 Or Me.StaffValue10 Then
Me.StaffValue6 = Null
Me.cboEmployee6 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee6.SetFocus
      Exit Sub
   End If
End Sub
Private Sub cboEmployee7_AfterUpdate()

Me.StaffValue7 = Me.cboEmployee7

If Me.cboEmployee7 = Me.StaffValue1 Or Me.StaffValue2 Or Me.StaffValue3 Or Me.StaffValue4 Or Me.StaffValue5 Or Me.StaffValue6 Or Me.StaffValue8 Or Me.StaffValue9 Or Me.StaffValue10 Then
Me.StaffValue7 = Null
Me.cboEmployee7 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee7.SetFocus
      Exit Sub
   End If
End Sub
Private Sub cboEmployee8_AfterUpdate()

Me.StaffValue8 = Me.cboEmployee8

If Me.cboEmployee8 = Me.StaffValue1 Or Me.StaffValue2 Or Me.StaffValue3 Or Me.StaffValue4 Or Me.StaffValue5 Or Me.StaffValue6 Or Me.StaffValue7 Or Me.StaffValue9 Or Me.StaffValue10 Then
Me.StaffValue8 = Null
Me.cboEmployee8 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee8.SetFocus
      Exit Sub
   End If
End Sub
Private Sub cboEmployee9_AfterUpdate()

Me.StaffValue9 = Me.cboEmployee9

If Me.cboEmployee9 = Me.StaffValue1 Or Me.StaffValue2 Or Me.StaffValue3 Or Me.StaffValue4 Or Me.StaffValue5 Or Me.StaffValue6 Or Me.StaffValue7 Or Me.StaffValue8 Or Me.StaffValue10 Then
Me.StaffValue9 = Null
Me.cboEmployee9 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee9.SetFocus
      Exit Sub
   End If
End Sub
Private Sub cboEmployee10_AfterUpdate()

Me.StaffValue10 = Me.cboEmployee10

If Me.cboEmployee10 = Me.StaffValue1 Or Me.StaffValue2 Or Me.StaffValue3 Or Me.StaffValue4 Or Me.StaffValue5 Or Me.StaffValue6 Or Me.StaffValue7 Or Me.StaffValue8 Or Me.StaffValue9 Then
Me.StaffValue10 = Null
Me.cboEmployee10 = Null
MsgBox "You all ready have assigned this name for allocation.", vbCritical + vbOKOnly + vbDefaultButton2, "Repeated Information"
      DoCmd.CancelEvent
    Me.cboEmployee10.SetFocus
      Exit Sub
   End If
End Sub

Answer : VBA if formula bringing up wrong results.

You aren't casting the addition and subtraction operators, you are casting the positive and negative notation and it just makes the assumption that the numeric part is 0.  +0 = + = 0
Random Solutions  
 
programming4us programming4us