PDA

View Full Version : Solved: Message box help



Lutoniall
12-10-2007, 04:01 AM
How do I stop the value going over 199.9 when a number is typed in an inputbox. Then it will display an error message. This is what ive got:

Number = InputBox("Enter price per litre")
If Len(Number) > 0.4 And Len(Number) < 199.9 Then
Response = MsgBox("The pence per litre can only be set up to 199.9", vbExclamation + vbOKCancel)
End If

This works a bit but the response comes up everytime I type in a number.

mattj
12-10-2007, 05:56 AM
Take out the LEN function -your counting the number of characters with that. Also, I suggest you change "Number" to something else - it is a reserved word in Access and could cuase you problems.


Number = InputBox("Enter price per litre")
If Number > 0.4 And Number < 199.9 Then
Response = MsgBox("The pence per litre can only be set up to 199.9", vbExclamation + vbOKCancel)
End If

DarkSprout
12-11-2007, 06:34 AM
Or Much Cleaner...


Do Until number > 0.4 And number <= 199.9
number = InputBox("The pence per litre can only be set up to 199.9", "Enter price per litre")
Loop

X-BRichard-X
12-15-2007, 07:54 AM
You could also have used a regular expression to easily solve this problem.

ofrazier
12-27-2007, 09:31 PM
Although using RegEx is handy, it does require more code, and thus will not be as efficient as the second response. For a onetime test, in my opinion, the shorter the better.