validation rule

C

Chuck216

Hi

I would like to place a validation rule on a form and can not figure out the
code.

What I want to do is:

If Me.wait8-9 >14 then
Me.hour8-9 must be >0

Thanks in advance for any help with this

Chuck
 
J

John W. Vinson

Hi

I would like to place a validation rule on a form and can not figure out the
code.

What I want to do is:

If Me.wait8-9 >14 then
Me.hour8-9 must be >0

Thanks in advance for any help with this

Chuck

I'd do this kind of validation in the Form's BeforeUpdate() event - this has a
Cancel operand, set it to True to block the update:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me![wait8-9] >14 Then
If NZ(Me![hour8-9]) = 0 Then
Cancel = True
MsgBox "You must fill in Hour8-9", vbOKOnly
Me![hour8-9].SetFocus
End If
End If
End Sub

I must say that these control names - especially if the correspond to
fieldnames - are worrisome; it looks like you're storing data in fieldnames,
never a good idea.
 
C

Chuck216

Thank you that works great!



John W. Vinson said:
Hi

I would like to place a validation rule on a form and can not figure out the
code.

What I want to do is:

If Me.wait8-9 >14 then
Me.hour8-9 must be >0

Thanks in advance for any help with this

Chuck

I'd do this kind of validation in the Form's BeforeUpdate() event - this has a
Cancel operand, set it to True to block the update:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me![wait8-9] >14 Then
If NZ(Me![hour8-9]) = 0 Then
Cancel = True
MsgBox "You must fill in Hour8-9", vbOKOnly
Me![hour8-9].SetFocus
End If
End If
End Sub

I must say that these control names - especially if the correspond to
fieldnames - are worrisome; it looks like you're storing data in fieldnames,
never a good idea.
 

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