Problems with Combo Box Value - Before the Update and After

C

chrisc

Morning,

I've been hacking away at this for a week now and am just not getting
anywhere! Some help would be greatly appreciated..

I have a form (P_Test) with a subform (P_Fault)

Users hit a button on the main form and it automatically adds the
correct number of records in the fault form, and gives them a serial
number.

Each record in the fault form is defaulted to pass (the pass comes from
a combobox called P_Fault_Type) - it is with this box that I am having
a problem.

Within the table for P_Test I have a field called PassFailTest - at the
start of the test this field is automatically given the same value as
the quantity - say 100 for arguments sake.

Now for the problem:

I need to update the value of PassFailTest by either adding,
subtracting or not touching the passfailtest field.

For Instance, if the current value is 'pass' and is changed to one of
the faults in the combo called 'Tombstone', the passfailtest field
should subtract 1, making it 99.

If the current value is 'Tombstone' and changed to pass the event
should add 1, making it 100 again.

I can get this part working fine, my MAJOR issue is that I cannot stop
it from adding or subtracting 1 when the user clicks the down arrow on
the combo and selects the same value again.

So, the current value is pass, and they select pass again from the list
- I now have 101 - which is impossible as only 100 were on test to
start with!

I have tried all kinds of If/ElseIf/Not's etc, and a lot of messing
around with a select case scenario but I just don't know what I need to
do. An example of the code im trying:

If CurrentValue = 1 Then
Select Case P_Fault_Type.ItemData(P_Fault_Type.ListIndex)

Case 0 'Pass 0
Counter = Counter + 0
Case 1 'Tombstone 1
Counter = Counter - 1
Case 2 'Missing 2
Counter = Counter - 1
Case 3 'Missing 2
Counter = Counter - 1
Case 4 'Missing 2
Counter = Counter - 1
Case 5 'Missing 2
Counter = Counter - 1
Case 6 'Missing 2
Counter = Counter - 1
Case 7 'Missing 2
Counter = Counter - 1
Case 8 'Missing 2

End Select

ElseIf CurrentValue = 2 Then
Select Case P_Fault_Type.ItemData(P_Fault_Type.ListIndex)

Case 1 'Pass 0
Counter = Counter + 1
Case 2 'Tombstone 1
Counter = Counter + 0
Case 3 'Missing 2
Counter = Counter - 1
Case 4 'Missing 2
Counter = Counter - 1
Case 5 'Missing 2
Counter = Counter - 1
Case 6 'Missing 2
Counter = Counter - 1
Case 7 'Missing 2
Counter = Counter - 1
Case 8 'Missing 2
Counter = Counter - 1
Case 9 'Missing 2

End Select
End If

Etc, etc...

Please, if anyone knows how I can make it see that the same value has
been selected again and it should not do anything, let me know..

Many thanks,

Chris.
 
M

Marshall Barton

I've been hacking away at this for a week now and am just not getting
anywhere! Some help would be greatly appreciated..

I have a form (P_Test) with a subform (P_Fault)

Users hit a button on the main form and it automatically adds the
correct number of records in the fault form, and gives them a serial
number.

Each record in the fault form is defaulted to pass (the pass comes from
a combobox called P_Fault_Type) - it is with this box that I am having
a problem.

Within the table for P_Test I have a field called PassFailTest - at the
start of the test this field is automatically given the same value as
the quantity - say 100 for arguments sake.

Now for the problem:

I need to update the value of PassFailTest by either adding,
subtracting or not touching the passfailtest field.

For Instance, if the current value is 'pass' and is changed to one of
the faults in the combo called 'Tombstone', the passfailtest field
should subtract 1, making it 99.

If the current value is 'Tombstone' and changed to pass the event
should add 1, making it 100 again.

I can get this part working fine, my MAJOR issue is that I cannot stop
it from adding or subtracting 1 when the user clicks the down arrow on
the combo and selects the same value again.

So, the current value is pass, and they select pass again from the list
- I now have 101 - which is impossible as only 100 were on test to
start with!

I have tried all kinds of If/ElseIf/Not's etc, and a lot of messing
around with a select case scenario but I just don't know what I need to
do. An example of the code im trying:

If CurrentValue = 1 Then
Select Case P_Fault_Type.ItemData(P_Fault_Type.ListIndex)

Case 0 'Pass 0
Counter = Counter + 0
Case 1 'Tombstone 1
Counter = Counter - 1
Case 2 'Missing 2
Counter = Counter - 1
Case 3 'Missing 2
Counter = Counter - 1
Case 4 'Missing 2
Counter = Counter - 1
Case 5 'Missing 2
Counter = Counter - 1
Case 6 'Missing 2
Counter = Counter - 1
Case 7 'Missing 2
Counter = Counter - 1
Case 8 'Missing 2

End Select

ElseIf CurrentValue = 2 Then
Select Case P_Fault_Type.ItemData(P_Fault_Type.ListIndex)

Case 1 'Pass 0
Counter = Counter + 1
Case 2 'Tombstone 1
Counter = Counter + 0
Case 3 'Missing 2
Counter = Counter - 1
Case 4 'Missing 2
Counter = Counter - 1
Case 5 'Missing 2
Counter = Counter - 1
Case 6 'Missing 2
Counter = Counter - 1
Case 7 'Missing 2
Counter = Counter - 1
Case 8 'Missing 2
Counter = Counter - 1
Case 9 'Missing 2

End Select
End If

Etc, etc...

Please, if anyone knows how I can make it see that the same value has
been selected again and it should not do anything, let me know..


You might want to investigate checnking the value against
the control's OldValue property.

However, I think you can probably avoid all this by waiting
to recalculate the value until the user exits the subform
and checking the final value of all the records.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top