I have five textboxes within one frame (DEMNO1 through DEMNO5). Each tectbox has an assigned tab index (0 through 4). The code for each textbox detects an error if data is non-numeric orif data is less than 5 digits. Each textbox's MaxLength is set at 5. What I can't get it to do is:
1. Keep the focus at that textbox until the error conditions have been removed. The focus always moves to the next Tab Index regardless of error, and
2. In tests, if user tabs out of the textbox without entering anything, the error condition is not detected. How can I trap an error if user doesn't enter anything?
3. Also, how can I force a decimal display (e.g. entering 75000 would display 750.00 instead of 750)? I've tried Dim as Currency and also DEMNO2 = Format(Val(DEMNO2), "###,###.00") with no luck.
THANKS to anyone for help. Here is the code.
Sub DEMNO2_afterupdate()
Dim NewVal As Integer
Dim IsNumber As Boolean
Dim IsLength As String
IsNumber = IsNumeric(DEMNO2)
IsLength = Len(DEMNO2)
If IsLength < 5 Then NewVal = 1
If IsLength > 4 Then NewVal = 0
If IsNumber = 0 Then NewVal = 1
If IsNumber = 1 Then NewVal = 0
If NewVal > 0 Then MsgBox "MUST BE FIVE DIGITS"
If NewVal > 0 Then DEMNO2.SetFocus
End Sub
1. Keep the focus at that textbox until the error conditions have been removed. The focus always moves to the next Tab Index regardless of error, and
2. In tests, if user tabs out of the textbox without entering anything, the error condition is not detected. How can I trap an error if user doesn't enter anything?
3. Also, how can I force a decimal display (e.g. entering 75000 would display 750.00 instead of 750)? I've tried Dim as Currency and also DEMNO2 = Format(Val(DEMNO2), "###,###.00") with no luck.
THANKS to anyone for help. Here is the code.
Sub DEMNO2_afterupdate()
Dim NewVal As Integer
Dim IsNumber As Boolean
Dim IsLength As String
IsNumber = IsNumeric(DEMNO2)
IsLength = Len(DEMNO2)
If IsLength < 5 Then NewVal = 1
If IsLength > 4 Then NewVal = 0
If IsNumber = 0 Then NewVal = 1
If IsNumber = 1 Then NewVal = 0
If NewVal > 0 Then MsgBox "MUST BE FIVE DIGITS"
If NewVal > 0 Then DEMNO2.SetFocus
End Sub