Validate data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to validate data on a form (A continuous form). I have put this
code in the BeforeUpdate event of the field:

Private Sub QtyLogOut_BeforeUpdate(Cancel As Integer)
Select Case Me![QtyLogOut]
Case Me![QtyLogOut] > Me![QtyOnHand]
MsgBox "You are trying to log out more than we have!", vbOKOnly
Cancel = True
End Select
End Sub

It does not appear to work. Can you give me suggestions.
 
What this code would try to do would be to compare the value of QtyLogOut to
the result of the Boolean expression QtyLogOut > QtyOnHand, which will
return either True (-1) or False (0). This is obviously not what you want.

When testing against just one condition, it would be simpler to drop the
Select Case and use If ... Then ...

If QtyLogOut > QtyOnHand Then
'show message and cancel
End If

If you're using Select Case because you expect to add further tests, you
could do something like this ...

Select Case True
Case QtyLogOut > QtyOnHand
MsgBox "Trying to log out more than we have!"
Cancel = True
Case QtyLogOut < 0
MsgBox "Can't log out a negative amount!"
Cancel = True
End Select
 
Thanks Brendan, that's very helpful.

Brendan Reynolds said:
What this code would try to do would be to compare the value of QtyLogOut to
the result of the Boolean expression QtyLogOut > QtyOnHand, which will
return either True (-1) or False (0). This is obviously not what you want.

When testing against just one condition, it would be simpler to drop the
Select Case and use If ... Then ...

If QtyLogOut > QtyOnHand Then
'show message and cancel
End If

If you're using Select Case because you expect to add further tests, you
could do something like this ...

Select Case True
Case QtyLogOut > QtyOnHand
MsgBox "Trying to log out more than we have!"
Cancel = True
Case QtyLogOut < 0
MsgBox "Can't log out a negative amount!"
Cancel = True
End Select

--
Brendan Reynolds (MVP)


Bonnie said:
I am trying to validate data on a form (A continuous form). I have put
this
code in the BeforeUpdate event of the field:

Private Sub QtyLogOut_BeforeUpdate(Cancel As Integer)
Select Case Me![QtyLogOut]
Case Me![QtyLogOut] > Me![QtyOnHand]
MsgBox "You are trying to log out more than we have!", vbOKOnly
Cancel = True
End Select
End Sub

It does not appear to work. Can you give me suggestions.
 

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

Back
Top