unlogic arthemetic error

Y

youssef

I did a simple code on a form that generate a message when the user enter
quantity return more than the quantity sold
the problem is that the code work correctly with some record but doesn't
work correctly with other record (the message apear if the user enter a
quantity less or more the the quantity return) and that happened when the
quantity is 10
which mean that this isn't an error in the code
the code on a button:

Private Sub Command8_Click()
Dim msg, stryle, title, response
msg = "the quantity return could not be more than the quantity sold"
title = "caution"
Style = 0
Me.Text9 = Me.List2.Column(3)
If Me.Text6 > Me.List2.Column(3) Then
response = MsgBox(msg, Style, title)
Else
DoCmd.Beep
End If

End Sub

which the fourth column in list2 is quantity
 
M

Marshall Barton

youssef said:
I did a simple code on a form that generate a message when the user enter
quantity return more than the quantity sold
the problem is that the code work correctly with some record but doesn't
work correctly with other record (the message apear if the user enter a
quantity less or more the the quantity return) and that happened when the
quantity is 10
which mean that this isn't an error in the code
the code on a button:

Private Sub Command8_Click()
Dim msg, stryle, title, response
msg = "the quantity return could not be more than the quantity sold"
title = "caution"
Style = 0
Me.Text9 = Me.List2.Column(3)
If Me.Text6 > Me.List2.Column(3) Then
response = MsgBox(msg, Style, title)
Else
DoCmd.Beep
End If

End Sub

which the fourth column in list2 is quantity


List/combo box columns are text values. Try converting it
to a number:
. . .
Me.Text9 = Val(Me.List2.Column(3))
If Me.Text6 > Me.Text9 Then
. . .
 
J

Jeanette Cunningham

Hi youssef,
usually this type of check is done in the Before Update event of the form
(not before update of the control, and not with a separate button).
Try something like the code below.
The Nz function puts a 0 for quantity if the control is Null.


Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim lngQuantitySold as Long

strMsg = "the quantity return could not be more than the quantity sold"
lngQuantitySold = Nz(Me.Text9,0)

If Nz(Me.Text6,0) > lngQuantitySold Then
MsgBox strMsg
Cancel = True
End If

End Sub

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

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