Validate textbox's with Form BeforeUdate

N

Neal Ostrander

I want to check the values in 5 textbox's on a form if the contain any number
other than 0 I want to check a 6th textbox to make sure its value is greater
than 0 also. I figured the form's BeforeUpdate would be the best place to do
this check but I am not quite sure how to set up the code to accomplish this
task.
Thanks for any help
Neal
 
K

Ken Snell

Example code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Textbox1.Value = 0 Then
Cancel = True
Me.Textbox1.SetFocus
MsgBox "Cannot have a 0 value in textbox1", vbOK, _
"Zero Not Allowed"
ElseIf Me.Textbox2.Value = 0 Then
Cancel = True
Me.Textbox2.SetFocus
MsgBox "Cannot have a 0 value in textbox2", vbOK, _
"Zero Not Allowed"
ElseIf Me.Textbox3.Value = 0 Then
Cancel = True
Me.Textbox3.SetFocus
MsgBox "Cannot have a 0 value in textbox3", vbOK, _
"Zero Not Allowed"
' continue with more ElseIf blocks as needed
End If
 
B

bhicks11 via AccessMonster.com

How about something like:

If not isnull(me.textbox1) and not isnull(me.textbox2) and not isnull(me.
textbox3) and not isnull(me.textbox4) and not isnull(me.textbox5) then
If isnull(me.text6) then
Do something else
End If
End If

Bonnie
http://www.dataplus-svc.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top