I have a form with a text box collected quantity information. My user (who isn't the friendliest and thinks I'm an idiot) reported an overflow error after "typing a simple '2'" in the box. I asked for his error log, and confirmed that was the error, and it occurred somewhere in this code:
Private Sub txtUnits_KeyPress(KeyAscii As Integer)
On Error GoTo txtUnits_KeyPress_Err
If KeyAscii = vbKeyReturn Then I want to save data and close the form if they hit the Enter key
If varOp = 1 Then ' (varOp is an integer, I set it to 0, 1, or 2 depending on how the form was opened)
cmdSave_Click
Exit Sub
End If
If varOp = 2 Then ' add
cmdAdd_Click
Exit Sub
End If
End If
If kP = 0 Then (kp is an integer, I set it to 0 or 1 to let me know this is the first time they input a decimal)
If KeyAscii = 46 Then
kP = 1
Exit Sub
End If
KeyAscii = checkNumeric(True, txtUnits.Text, KeyAscii)
Else
KeyAscii = checkNumeric(True, txtUnits.Text, KeyAscii)
End If
Exit Sub
I'm stumped. I can't recreate the error and no other user has reported it, but I also can't deny the error log, which clearly ties it to this sub on this form. checkNumeric is a function borrowed from this form, used in many other places in my code without any issues.
I've tried inputting all kinds of other keys (F2, 2 without NumLock, etc.) and can't get an error. Does anyone have a clue what I'm doing wrong? Or, should I just trap for error 6 and Resume Next?
Thank you for any help!
Private Sub txtUnits_KeyPress(KeyAscii As Integer)
On Error GoTo txtUnits_KeyPress_Err
If KeyAscii = vbKeyReturn Then I want to save data and close the form if they hit the Enter key
If varOp = 1 Then ' (varOp is an integer, I set it to 0, 1, or 2 depending on how the form was opened)
cmdSave_Click
Exit Sub
End If
If varOp = 2 Then ' add
cmdAdd_Click
Exit Sub
End If
End If
If kP = 0 Then (kp is an integer, I set it to 0 or 1 to let me know this is the first time they input a decimal)
If KeyAscii = 46 Then
kP = 1
Exit Sub
End If
KeyAscii = checkNumeric(True, txtUnits.Text, KeyAscii)
Else
KeyAscii = checkNumeric(True, txtUnits.Text, KeyAscii)
End If
Exit Sub
I'm stumped. I can't recreate the error and no other user has reported it, but I also can't deny the error log, which clearly ties it to this sub on this form. checkNumeric is a function borrowed from this form, used in many other places in my code without any issues.
I've tried inputting all kinds of other keys (F2, 2 without NumLock, etc.) and can't get an error. Does anyone have a clue what I'm doing wrong? Or, should I just trap for error 6 and Resume Next?
Thank you for any help!