SOLVED: Need an error message
Hi everyone,
This has got me stumped but that's easy to do! I have written an estimating program for a particular printing printing press. I have limited the number of press sheets to estimate at 500! Anything over 500 press sheets will not compute a final price and that's fine. What I am trying to do is to have an error message saying, let's say for now " Do Not Enter Over 500 Sheets" appear if the total of press sheet exceeds the 500 cut off quantity. The number of press sheets shows on the form in a text box that is formatted as a general number. I have tried variations of if and end if codes and I can get it to show the string, but it pops up on any amount, not just the amounts over 500. Well that's the jest of it. Any help would certainly be appreciated.
Thanks
Gary
Validating Numerical Data Entry
To disallow any data entry problems, you can set the vaildation rule for a field (using the table design view). Set it to: <=500
In the textbox on the form where you do not want a user to enter a value >500, then in the BeforeUpdate event enter something like this
[vba]Private Sub txtValue_BeforeUpdate(Cancel As Integer)
If Me.txtValue > 500 Then
MsgBox "Do Not Enter Over 500 Sheets", vbCritical, "Please re-enter."
Me.txtValue.SetFocus
End If
End Sub[/vba]The value that was entered in the textbox will remain there but not update until a value <= 500 is entered. Pressing ESC will return it to the original value before the invalid value was entered.
I think it is better to enter data using a form and use the BefureUpdate event code as you have more control over the error message diplayed.
I hope I understood your question. If not, post back. I (or someone else) will try to help.