unlogic arthemetic error

  • Thread starter Thread starter youssef
  • Start date Start date
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
 
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
. . .
 
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
 
Back
Top