Hello,
On a form I have multiple text boxes, all of which must contain data so that a calculation can be made and put into the answer text box. I have code that permits only numbers to be entered into the text boxes, however, I do not have code to prevent the boxes from being left empty. I have placed what I thought was the correct code in a number of places but none have worked. I would like a message box to pop up as soon as the user bypasses the box, whether the Tab or Enter-key is used. After the user acknowledges the msgbox, they are returned to the empty field. This is the code:
Private Sub bd_keyPress(KeyAscii As Integer)
If KeyAscii > 45 And KeyAscii < 58 Or KeyAscii = 8 Or KeyAscii = 13 Then
If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If
Else
KeyAscii = 0
End If
If bd.Text = " " Then
MsgBox "Each field requires data," + vbOKOnly, vbExclamation, "Error"
bd.SetFocus
End If
End Sub
Thanks in advance...
ONeal
On a form I have multiple text boxes, all of which must contain data so that a calculation can be made and put into the answer text box. I have code that permits only numbers to be entered into the text boxes, however, I do not have code to prevent the boxes from being left empty. I have placed what I thought was the correct code in a number of places but none have worked. I would like a message box to pop up as soon as the user bypasses the box, whether the Tab or Enter-key is used. After the user acknowledges the msgbox, they are returned to the empty field. This is the code:
Private Sub bd_keyPress(KeyAscii As Integer)
If KeyAscii > 45 And KeyAscii < 58 Or KeyAscii = 8 Or KeyAscii = 13 Then
If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If
Else
KeyAscii = 0
End If
If bd.Text = " " Then
MsgBox "Each field requires data," + vbOKOnly, vbExclamation, "Error"
bd.SetFocus
End If
End Sub
Thanks in advance...
ONeal