PDA

View Full Version : Solved: Testing entries in a text box



austenr
03-06-2010, 02:12 PM
The following throws an error when debugging:


If txtHoursWorked.Text < 5 Or txtHoursWorked.Text > 60 Then
MsgBox("Hours worked must be at least 5 and no more than 60.", , "Input Error")
End If


What's the correct syntax? Thanks

lucas
03-06-2010, 02:19 PM
Maybe:
Dim response As String
If txtHoursWorked.Text < 5 Or txtHoursWorked.Text > 60 Then
response = MsgBox("Hours worked must be at least 5 and no more than 60.", , "Input Error")
End If

austenr
03-06-2010, 02:22 PM
Does what I posted look right? Basically want to test if the user entered a number from 5 up to and including 60.

lucas
03-06-2010, 02:30 PM
Seems like that's exactly what it does. I added a few lines:

Dim response As String
If txtHoursWorked.Text < 5 Or txtHoursWorked.Text > 60 Then
response = MsgBox("Hours worked must be at least 5 and no more than 60.", , "Input Error")
txtHoursWorked.Text = ""
txtHoursWorked.SetFocus
Exit Sub
Else
MsgBox txtHoursWorked & " Hours Worked"
txtHoursWorked.Text = ""
End If

see attached to test

austenr
03-06-2010, 03:04 PM
Thanks Steve. Works great.

lucas
03-06-2010, 04:02 PM
Glad to help.

Keep your stick on the ice.