Premise: Performing comparisons between two textboxes, one in a subform, one in a parent form, during the subform textbox's AfterUpdate event. When making this comparison, illogical results are returned.
Objective: Return legitimate comparisons between the values contained within these two controls.
Progress:
The following code shows an example of code and apparent, illegitimate results outputted to the Immediate window.
Code:
Debug.Print IsNumeric(textBurnup) & IsNumeric(Parent!textBurnupLimit), _
textBurnup & ">" & Parent!textBurnupLimit & " = " & _
(textBurnup > Parent!textBurnupLimit)
textBurnup = Parent!textBurnupLimit - 100
Debug.Print IsNumeric(textBurnup) & IsNumeric(Parent!textBurnupLimit), _
textBurnup & ">" & Parent!textBurnupLimit & " = " & _
(textBurnup > Parent!textBurnupLimit)
Results:
TrueTrue 100>21500 = True
TrueTrue 21400>21500 = False`
Things I have tried:
- Setting textbox format to 'general number'. Fixes problem but I dont want to have to do this.
- Performing an arithmetic operation on either control. Fixes problem but I dont want to have to do this.
- Using either controls' .Value property. Doesn't work.
- Substituting a number in for the Parent!textbox. Works. Defeats the purpose of looking at the Parent's textbox.
- A few other things I can't think of now because I am just too surprised that I managed to break logic.
The textboxes are both numbers and should be comparable. Why is this happening? Why does setting one of their formats to 'general number' fix it?
Related articles:
String Compare Logic (based on answers below)
Source Info:
Coding Horror (based on answers below)