I need to validate input users enter via an InputBox, and if it is out of range, have a msgbox pop up and tell them to enter the data in the proper range
So far i can get it to do all of that, EXCEPT after it pops up the error, it enters that data into the form and continues on.
As soon as I enter cancel= true under the error message code, VB gives me a compile error.
If you dont enter any data and choose cancel, it gives you a type mismatch error.
Any ideas?
quote:
--------------------------------------------------------------------------------
intCount = 0
intTotalRoomsOcc = 0
Do While intCount <= 7
strInput = InputBox("Enter number of rooms occupied for floor " & _
FormatNumber((intCount) + 1, 0), "Occupency Needed")
If strInput = "" Or strInput > 30 Then
MsgBox "Please enter a Value between 0 and 30", vbOKOnly, "Input Error"
Cancel = True
End If
intRoomData = Val(strInput)
lblRoomsOcc(intCount).Caption = intRoomData
dblOccRate = intRoomData / 30
lblOccRate(intCount).Caption = FormatPercent(dblOccRate)
intTotalRoomsOcc = intTotalRoomsOcc + intRoomData
lblTotalRoomsOcc.Caption = intTotalRoomsOcc
dblOccSubTotal = intTotalRoomsOcc / 240
lblTotalOccRate.Caption = FormatPercent(dblOccSubTotal)
intCount = intCount + 1
Loop
End Sub
--------------------------------------------------------------------------------
So far i can get it to do all of that, EXCEPT after it pops up the error, it enters that data into the form and continues on.
As soon as I enter cancel= true under the error message code, VB gives me a compile error.
If you dont enter any data and choose cancel, it gives you a type mismatch error.
Any ideas?
quote:
--------------------------------------------------------------------------------
intCount = 0
intTotalRoomsOcc = 0
Do While intCount <= 7
strInput = InputBox("Enter number of rooms occupied for floor " & _
FormatNumber((intCount) + 1, 0), "Occupency Needed")
If strInput = "" Or strInput > 30 Then
MsgBox "Please enter a Value between 0 and 30", vbOKOnly, "Input Error"
Cancel = True
End If
intRoomData = Val(strInput)
lblRoomsOcc(intCount).Caption = intRoomData
dblOccRate = intRoomData / 30
lblOccRate(intCount).Caption = FormatPercent(dblOccRate)
intTotalRoomsOcc = intTotalRoomsOcc + intRoomData
lblTotalRoomsOcc.Caption = intTotalRoomsOcc
dblOccSubTotal = intTotalRoomsOcc / 240
lblTotalOccRate.Caption = FormatPercent(dblOccSubTotal)
intCount = intCount + 1
Loop
End Sub
--------------------------------------------------------------------------------