Help with code problem on form

R

Randy

I have a form which includes the following 4 fields all numbers: [Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent a
negative number from occuring in [FM]. [Edible], [Ined] and [FM] must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3, Ined=12.9, FM=0.
This example equals exactly 3000.2 but my message box is popping up. If
the [Sample] data entry is exactly 3000 or any other number without tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub
 
R

RuralGuy

You could easily be up against a timing problem. I'm assuming your control
source for the [FM] *control* (records have fields, forms have controls) is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access will update the
[FM] control before you leave the [Ined] control. Maybe and maybe not. I
suppose you could issue a DoEvents to give Access some time but there is a far
better solution: Your code should be in the BeforeUpdate event of the *Form*
and not the control. All of the controls will be up to date before Access
attempts to save the record. That is where you make your test and Cancel the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers: [Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent a
negative number from occuring in [FM]. [Edible], [Ined] and [FM] must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3, Ined=12.9, FM=0.
This example equals exactly 3000.2 but my message box is popping up. If
the [Sample] data entry is exactly 3000 or any other number without tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

Randy

I tried your suggestion in the before event of my form, but the msgbox still
pops up even though [FM] is not less than 0...Could it be something in th
rounding of numbers? Entries are now in tenths. Previously entries were in
whole numbers (3000.0) Ive used this code for 3 years without any problems.
But when entries are to the tenth, msgbox pops up, but not always. works
great if all entries are in whole numbers, not to the tenth...Randy
You could easily be up against a timing problem. I'm assuming your
control
source for the [FM] *control* (records have fields, forms have controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe not. I
suppose you could issue a DoEvents to give Access some time but there is a
far
better solution: Your code should be in the BeforeUpdate event of the
*Form*
and not the control. All of the controls will be up to date before Access
attempts to save the record. That is where you make your test and Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent a
negative number from occuring in [FM]. [Edible], [Ined] and [FM] must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3, Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping up. If
the [Sample] data entry is exactly 3000 or any other number without
tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The
Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

I forgot to mention that you are using < 0 rather than <> 0. I would change it.
If my assumptions are correct, I don't believe any rounding is taking place
unless you are doing some multiplication or division somewhere. Still I use the
Currency data type whenever 4 decimal places will do and I do my own rounding.

As a diagnostic, put a MsgBox just after the test to display [FM] and see what
is in there.

I tried your suggestion in the before event of my form, but the msgbox still
pops up even though [FM] is not less than 0...Could it be something in th
rounding of numbers? Entries are now in tenths. Previously entries were in
whole numbers (3000.0) Ive used this code for 3 years without any problems.
But when entries are to the tenth, msgbox pops up, but not always. works
great if all entries are in whole numbers, not to the tenth...Randy
You could easily be up against a timing problem. I'm assuming your
control
source for the [FM] *control* (records have fields, forms have controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe not. I
suppose you could issue a DoEvents to give Access some time but there is a
far
better solution: Your code should be in the BeforeUpdate event of the
*Form*
and not the control. All of the controls will be up to date before Access
attempts to save the record. That is where you make your test and Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent a
negative number from occuring in [FM]. [Edible], [Ined] and [FM] must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3, Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping up. If
the [Sample] data entry is exactly 3000 or any other number without
tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The
Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

Randy

I need <0 because [FM] is frequently 0 or more than 0 but it can never be
less than 0 (-0)
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is taking
place
unless you are doing some multiplication or division somewhere. Still I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM] and see
what
is in there.

I tried your suggestion in the before event of my form, but the msgbox
still
pops up even though [FM] is not less than 0...Could it be something in th
rounding of numbers? Entries are now in tenths. Previously entries were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
You could easily be up against a timing problem. I'm assuming your
control
source for the [FM] *control* (records have fields, forms have controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe not.
I
suppose you could issue a DoEvents to give Access some time but there is
a
far
better solution: Your code should be in the BeforeUpdate event of the
*Form*
and not the control. All of the controls will be up to date before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.



I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent a
negative number from occuring in [FM]. [Edible], [Ined] and [FM] must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3, Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping up.
If
the [Sample] data entry is exactly 3000 or any other number without
tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The
Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the
MsgBox test?

I need <0 because [FM] is frequently 0 or more than 0 but it can never be
less than 0 (-0)
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is taking
place
unless you are doing some multiplication or division somewhere. Still I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM] and see
what
is in there.

I tried your suggestion in the before event of my form, but the msgbox
still
pops up even though [FM] is not less than 0...Could it be something in th
rounding of numbers? Entries are now in tenths. Previously entries were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming your
control
source for the [FM] *control* (records have fields, forms have controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe not.
I
suppose you could issue a DoEvents to give Access some time but there is
a
far
better solution: Your code should be in the BeforeUpdate event of the
*Form*
and not the control. All of the controls will be up to date before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.



I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent a
negative number from occuring in [FM]. [Edible], [Ined] and [FM] must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3, Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping up.
If
the [Sample] data entry is exactly 3000 or any other number without
tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The
Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

Randy

Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try
the
MsgBox test?

I need <0 because [FM] is frequently 0 or more than 0 but it can never
be
less than 0 (-0)
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is taking
place
unless you are doing some multiplication or division somewhere. Still I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM] and
see
what
is in there.


I tried your suggestion in the before event of my form, but the msgbox
still
pops up even though [FM] is not less than 0...Could it be something in
th
rounding of numbers? Entries are now in tenths. Previously entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe
not.
I
suppose you could issue a DoEvents to give Access some time but there
is
a
far
better solution: Your code should be in the BeforeUpdate event of the
*Form*
and not the control. All of the controls will be up to date before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent a
negative number from occuring in [FM]. [Edible], [Ined] and [FM] must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3, Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping up.
If
the [Sample] data entry is exactly 3000 or any other number without
tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The
Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers so you can
see what is going on!

Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try
the
MsgBox test?

I need <0 because [FM] is frequently 0 or more than 0 but it can never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is taking
place
unless you are doing some multiplication or division somewhere. Still I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM] and
see
what
is in there.


I tried your suggestion in the before event of my form, but the msgbox
still
pops up even though [FM] is not less than 0...Could it be something in
th
rounding of numbers? Entries are now in tenths. Previously entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe
not.
I
suppose you could issue a DoEvents to give Access some time but there
is
a
far
better solution: Your code should be in the BeforeUpdate event of the
*Form*
and not the control. All of the controls will be up to date before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent a
negative number from occuring in [FM]. [Edible], [Ined] and [FM] must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3, Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping up.
If
the [Sample] data entry is exactly 3000 or any other number without
tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The
Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

Randy

I get a message of: [FM] is equal to <-4.54747350886464E-13>

Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers so
you can
see what is going on!

Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try
the
MsgBox test?


I need <0 because [FM] is frequently 0 or more than 0 but it can never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is taking
place
unless you are doing some multiplication or division somewhere. Still
I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM] and
see
what
is in there.


I tried your suggestion in the before event of my form, but the msgbox
still
pops up even though [FM] is not less than 0...Could it be something in
th
rounding of numbers? Entries are now in tenths. Previously entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event of
the
*Form*
and not the control. All of the controls will be up to date before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and [FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping up.
If
the [Sample] data entry is exactly 3000 or any other number without
tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The
Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.

I get a message of: [FM] is equal to <-4.54747350886464E-13>

Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers so
you can
see what is going on!

Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try
the
MsgBox test?


I need <0 because [FM] is frequently 0 or more than 0 but it can never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is taking
place
unless you are doing some multiplication or division somewhere. Still
I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM] and
see
what
is in there.


I tried your suggestion in the before event of my form, but the msgbox
still
pops up even though [FM] is not less than 0...Could it be something in
th
rounding of numbers? Entries are now in tenths. Previously entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event of
the
*Form*
and not the control. All of the controls will be up to date before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and [FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping up.
If
the [Sample] data entry is exactly 3000 or any other number without
tenths,
everything works fine. Any ideas what is happening? Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed The
Sample
Size. Foreign Material Has a Negative Number. Please Correct Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

Randy

[FM] has on control source: =[Sample]-([Edible]+[Ined])

Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.

I get a message of: [FM] is equal to <-4.54747350886464E-13>

Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers so
you can
see what is going on!


Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you
try
the
MsgBox test?


I need <0 because [FM] is frequently 0 or more than 0 but it can
never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is
taking
place
unless you are doing some multiplication or division somewhere.
Still
I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM]
and
see
what
is in there.

I tried your suggestion in the before event of my form, but the
msgbox
still
pops up even though [FM] is not less than 0...Could it be something
in
th
rounding of numbers? Entries are now in tenths. Previously entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming
your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event of
the
*Form*
and not the control. All of the controls will be up to date
before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to
prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and [FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping
up.
If
the [Sample] data entry is exactly 3000 or any other number
without
tenths,
everything works fine. Any ideas what is happening?
Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed
The
Sample
Size. Foreign Material Has a Negative Number. Please Correct
Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

Addition and subtraction won't do it. Have you changed your Format on each of
the controls to General Number with Auto decimal? That should show you what you
are working with.

[FM] has on control source: =[Sample]-([Edible]+[Ined])

Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.

I get a message of: [FM] is equal to <-4.54747350886464E-13>

<RuralGuy> wrote in message
Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers so
you can
see what is going on!


Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you
try
the
MsgBox test?


I need <0 because [FM] is frequently 0 or more than 0 but it can
never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is
taking
place
unless you are doing some multiplication or division somewhere.
Still
I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM]
and
see
what
is in there.

I tried your suggestion in the before event of my form, but the
msgbox
still
pops up even though [FM] is not less than 0...Could it be something
in
th
rounding of numbers? Entries are now in tenths. Previously entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming
your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event of
the
*Form*
and not the control. All of the controls will be up to date
before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to
prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and [FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping
up.
If
the [Sample] data entry is exactly 3000 or any other number
without
tenths,
everything works fine. Any ideas what is happening?
Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed
The
Sample
Size. Foreign Material Has a Negative Number. Please Correct
Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

Randy

The numbers seem to look alright. Scrolling through the records some of FM
has numbers such as 6.000 instead of 6.0. The record I'm experimenting
right now shows [FM] as: <-4.54747350886464E-13> where it should be 0.0. I
don't know why the code doesn't work when I use numbers to the tenth...Randy

Addition and subtraction won't do it. Have you changed your Format on
each of
the controls to General Number with Auto decimal? That should show you
what you
are working with.

[FM] has on control source: =[Sample]-([Edible]+[Ined])

Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.


I get a message of: [FM] is equal to <-4.54747350886464E-13>

<RuralGuy> wrote in message
Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers
so
you can
see what is going on!


Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you
try
the
MsgBox test?

I need <0 because [FM] is frequently 0 or more than 0 but it can
never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I
would
change it.
If my assumptions are correct, I don't believe any rounding is
taking
place
unless you are doing some multiplication or division somewhere.
Still
I
use the
Currency data type whenever 4 decimal places will do and I do my
own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM]
and
see
what
is in there.

I tried your suggestion in the before event of my form, but the
msgbox
still
pops up even though [FM] is not less than 0...Could it be
something
in
th
rounding of numbers? Entries are now in tenths. Previously
entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not
always.
works
great if all entries are in whole numbers, not to the
tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming
your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and
maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event
of
the
*Form*
and not the control. All of the controls will be up to date
before
Access
attempts to save the record. That is where you make your test
and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to
prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and
[FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping
up.
If
the [Sample] data entry is exactly 3000 or any other number
without
tenths,
everything works fine. Any ideas what is happening?
Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed
The
Sample
Size. Foreign Material Has a Negative Number. Please Correct
Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

You can truncate to 1 decimal by putting something like the following
in the AfterUpdate event of the controls where the user enters values:

Me.FM = Int(Me.FM * 10) / 10


[FM] has on control source: =[Sample]-([Edible]+[Ined])

Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.

I get a message of: [FM] is equal to <-4.54747350886464E-13>

<RuralGuy> wrote in message
Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers so
you can
see what is going on!


Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you
try
the
MsgBox test?


I need <0 because [FM] is frequently 0 or more than 0 but it can
never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I would
change it.
If my assumptions are correct, I don't believe any rounding is
taking
place
unless you are doing some multiplication or division somewhere.
Still
I
use the
Currency data type whenever 4 decimal places will do and I do my own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM]
and
see
what
is in there.

I tried your suggestion in the before event of my form, but the
msgbox
still
pops up even though [FM] is not less than 0...Could it be something
in
th
rounding of numbers? Entries are now in tenths. Previously entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not always.
works
great if all entries are in whole numbers, not to the tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming
your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event of
the
*Form*
and not the control. All of the controls will be up to date
before
Access
attempts to save the record. That is where you make your test and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to
prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and [FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping
up.
If
the [Sample] data entry is exactly 3000 or any other number
without
tenths,
everything works fine. Any ideas what is happening?
Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed
The
Sample
Size. Foreign Material Has a Negative Number. Please Correct
Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

You might also want to look at the query/table data directly rather than using
the form. You might see something different.

The numbers seem to look alright. Scrolling through the records some of FM
has numbers such as 6.000 instead of 6.0. The record I'm experimenting
right now shows [FM] as: <-4.54747350886464E-13> where it should be 0.0. I
don't know why the code doesn't work when I use numbers to the tenth...Randy

Addition and subtraction won't do it. Have you changed your Format on
each of
the controls to General Number with Auto decimal? That should show you
what you
are working with.

[FM] has on control source: =[Sample]-([Edible]+[Ined])

<RuralGuy> wrote in message
Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.


I get a message of: [FM] is equal to <-4.54747350886464E-13>

<RuralGuy> wrote in message
Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers
so
you can
see what is going on!


Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you
try
the
MsgBox test?

I need <0 because [FM] is frequently 0 or more than 0 but it can
never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I
would
change it.
If my assumptions are correct, I don't believe any rounding is
taking
place
unless you are doing some multiplication or division somewhere.
Still
I
use the
Currency data type whenever 4 decimal places will do and I do my
own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM]
and
see
what
is in there.

I tried your suggestion in the before event of my form, but the
msgbox
still
pops up even though [FM] is not less than 0...Could it be
something
in
th
rounding of numbers? Entries are now in tenths. Previously
entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not
always.
works
great if all entries are in whole numbers, not to the
tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming
your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and
maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event
of
the
*Form*
and not the control. All of the controls will be up to date
before
Access
attempts to save the record. That is where you make your test
and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to
prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and
[FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping
up.
If
the [Sample] data entry is exactly 3000 or any other number
without
tenths,
everything works fine. Any ideas what is happening?
Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed
The
Sample
Size. Foreign Material Has a Negative Number. Please Correct
Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

I don't know the history of your mdb but when things start working weirdly I
usually recopmmend reviewing the suggestions of MVP Allen Browne here:
http://allenbrowne.com/ser-47.html

Especially turning off Name Auto-Correct and doing a decompile and then a
compact and repair.

The numbers seem to look alright. Scrolling through the records some of FM
has numbers such as 6.000 instead of 6.0. The record I'm experimenting
right now shows [FM] as: <-4.54747350886464E-13> where it should be 0.0. I
don't know why the code doesn't work when I use numbers to the tenth...Randy

Addition and subtraction won't do it. Have you changed your Format on
each of
the controls to General Number with Auto decimal? That should show you
what you
are working with.

[FM] has on control source: =[Sample]-([Edible]+[Ined])

<RuralGuy> wrote in message
Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.


I get a message of: [FM] is equal to <-4.54747350886464E-13>

<RuralGuy> wrote in message
Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers
so
you can
see what is going on!


Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you
try
the
MsgBox test?

I need <0 because [FM] is frequently 0 or more than 0 but it can
never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I
would
change it.
If my assumptions are correct, I don't believe any rounding is
taking
place
unless you are doing some multiplication or division somewhere.
Still
I
use the
Currency data type whenever 4 decimal places will do and I do my
own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM]
and
see
what
is in there.

I tried your suggestion in the before event of my form, but the
msgbox
still
pops up even though [FM] is not less than 0...Could it be
something
in
th
rounding of numbers? Entries are now in tenths. Previously
entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not
always.
works
great if all entries are in whole numbers, not to the
tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming
your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and
maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event
of
the
*Form*
and not the control. All of the controls will be up to date
before
Access
attempts to save the record. That is where you make your test
and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to
prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and
[FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping
up.
If
the [Sample] data entry is exactly 3000 or any other number
without
tenths,
everything works fine. Any ideas what is happening?
Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed
The
Sample
Size. Foreign Material Has a Negative Number. Please Correct
Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

Randy

Truncate as you suggested did the trick. It is working the way i want it
to. Thanks for your help...Randy
You can truncate to 1 decimal by putting something like the following
in the AfterUpdate event of the controls where the user enters values:

Me.FM = Int(Me.FM * 10) / 10


[FM] has on control source: =[Sample]-([Edible]+[Ined])

Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.


I get a message of: [FM] is equal to <-4.54747350886464E-13>

<RuralGuy> wrote in message
Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers
so
you can
see what is going on!


Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you
try
the
MsgBox test?

I need <0 because [FM] is frequently 0 or more than 0 but it can
never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I
would
change it.
If my assumptions are correct, I don't believe any rounding is
taking
place
unless you are doing some multiplication or division somewhere.
Still
I
use the
Currency data type whenever 4 decimal places will do and I do my
own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM]
and
see
what
is in there.

I tried your suggestion in the before event of my form, but the
msgbox
still
pops up even though [FM] is not less than 0...Could it be
something
in
th
rounding of numbers? Entries are now in tenths. Previously
entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not
always.
works
great if all entries are in whole numbers, not to the
tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming
your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and
maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event
of
the
*Form*
and not the control. All of the controls will be up to date
before
Access
attempts to save the record. That is where you make your test
and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to
prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and
[FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping
up.
If
the [Sample] data entry is exactly 3000 or any other number
without
tenths,
everything works fine. Any ideas what is happening?
Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed
The
Sample
Size. Foreign Material Has a Negative Number. Please Correct
Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
R

RuralGuy

Glad I could help.

Truncate as you suggested did the trick. It is working the way i want it
to. Thanks for your help...Randy
You can truncate to 1 decimal by putting something like the following
in the AfterUpdate event of the controls where the user enters values:

Me.FM = Int(Me.FM * 10) / 10


[FM] has on control source: =[Sample]-([Edible]+[Ined])

<RuralGuy> wrote in message
Well that is definately less that zero! Do you do any multiplication or
division on any of these numbers? You may have to clean up your data.


I get a message of: [FM] is equal to <-4.54747350886464E-13>

<RuralGuy> wrote in message
Here's how you put the Diagnostic code in the Form BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then

'*** Diagnostic code on the following line
MsgBox "[FM] is equal to <" & [FM] & ">"
'*** End of diagnostic code

MsgBox "Edible Kernels and/or Inedible Kernels Exceed the " & _
" Sample Size. Foreign Material Has a Negative " & _
"Number. Please Correct Edible or Inedible Kernels."
Cancel = True
End If

End Sub

For now, take the Format Fixed off and change them to General Numbers
so
you can
see what is going on!


Numbers, Format fixed, decimal places 1, Double integer in table
I dont know how to do the msgBox test...Randy
<RuralGuy> wrote in message
Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you
try
the
MsgBox test?

I need <0 because [FM] is frequently 0 or more than 0 but it can
never
be
less than 0 (-0)
<RuralGuy> wrote in message
I forgot to mention that you are using < 0 rather than <> 0. I
would
change it.
If my assumptions are correct, I don't believe any rounding is
taking
place
unless you are doing some multiplication or division somewhere.
Still
I
use the
Currency data type whenever 4 decimal places will do and I do my
own
rounding.

As a diagnostic, put a MsgBox just after the test to display [FM]
and
see
what
is in there.

I tried your suggestion in the before event of my form, but the
msgbox
still
pops up even though [FM] is not less than 0...Could it be
something
in
th
rounding of numbers? Entries are now in tenths. Previously
entries
were
in
whole numbers (3000.0) Ive used this code for 3 years without any
problems.
But when entries are to the tenth, msgbox pops up, but not
always.
works
great if all entries are in whole numbers, not to the
tenth...Randy
<RuralGuy> wrote in message
You could easily be up against a timing problem. I'm assuming
your
control
source for the [FM] *control* (records have fields, forms have
controls)
is a
formula like =[Sample]-[Edible]-[Ined]. You are assuming Access
will
update the
[FM] control before you leave the [Ined] control. Maybe and
maybe
not.
I
suppose you could issue a DoEvents to give Access some time but
there
is
a
far
better solution: Your code should be in the BeforeUpdate event
of
the
*Form*
and not the control. All of the controls will be up to date
before
Access
attempts to save the record. That is where you make your test
and
Cancel
the
event if you do not like the results of the test.


I have a form which includes the following 4 fields all numbers:
[Sample],
[Edible], [Ined], and [FM] I have code in before update to
prevent
a
negative number from occuring in [FM]. [Edible], [Ined] and
[FM]
must
equall [Sample]. Example: Sample=3000.2, Edible=2987.3,
Ined=12.9,
FM=0.
This example equals exactly 3000.2 but my message box is popping
up.
If
the [Sample] data entry is exactly 3000 or any other number
without
tenths,
everything works fine. Any ideas what is happening?
Thanks...Randy

Private Sub InedibleKernelslbl_BeforeUpdate(Cancel As Integer)
If [FM] < 0 Then
If MsgBox("Edible Kernels and/or Inedible Kernels Exceed
The
Sample
Size. Foreign Material Has a Negative Number. Please Correct
Edible
or
Inedible Kernels.", vbYes + vbDefaultButton2) <> vbYes Then
'Cancel = True
End If
End If
End Sub


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.


_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
J

John Vinson

The numbers seem to look alright. Scrolling through the records some of FM
has numbers such as 6.000 instead of 6.0. The record I'm experimenting
right now shows [FM] as: <-4.54747350886464E-13> where it should be 0.0. I
don't know why the code doesn't work when I use numbers to the tenth...Randy

Pardon me for jumping in, RuralGuy - but this is expected behavior
given the datatype Randy's using.

Double Float numbers, which you're evidently using, are
APPROXIMATIONS. Just as the number 1/7 cannot be depicted exactly as a
decimal fraction, the number 0.1 cannot be represented exactly as a
binary fraction - and binary fractions are exactly how Floats and
Doubles are stored. Any number is accurate to some fourteen decimals
of precision (the accuracy of a 48-bit number); a sum of numbers with
that precision will have about that much "fuzz".

The simplest getaround is to change the datatype of your fields from
Number(Double) to Currency. This isn't the Currency *format*, it's a
currency *datatype* - actually stored as a scaled huge integer with
exactly four decimal places, no more, no fewer, and without this kind
of roundoff error.

A bit more work would be to test for the absolute value of the sum
being less than some epsilon (say 0.01, if you're only interested in
tenths accuracy) rather than testing it for equality to 0.

John W. Vinson[MVP]
 
R

RuralGuy

Thanks for the update John. I knew there was a reason I use Currency as often
as I can. I'm sure Randy appreciates the knowledge as well. Hopefully Randy is
still monitoring this thread and will heed your sage advice. I know I will.

The numbers seem to look alright. Scrolling through the records some of FM
has numbers such as 6.000 instead of 6.0. The record I'm experimenting
right now shows [FM] as: <-4.54747350886464E-13> where it should be 0.0. I
don't know why the code doesn't work when I use numbers to the tenth...Randy

Pardon me for jumping in, RuralGuy - but this is expected behavior
given the datatype Randy's using.

Double Float numbers, which you're evidently using, are
APPROXIMATIONS. Just as the number 1/7 cannot be depicted exactly as a
decimal fraction, the number 0.1 cannot be represented exactly as a
binary fraction - and binary fractions are exactly how Floats and
Doubles are stored. Any number is accurate to some fourteen decimals
of precision (the accuracy of a 48-bit number); a sum of numbers with
that precision will have about that much "fuzz".

The simplest getaround is to change the datatype of your fields from
Number(Double) to Currency. This isn't the Currency *format*, it's a
currency *datatype* - actually stored as a scaled huge integer with
exactly four decimal places, no more, no fewer, and without this kind
of roundoff error.

A bit more work would be to test for the absolute value of the sum
being less than some epsilon (say 0.01, if you're only interested in
tenths accuracy) rather than testing it for equality to 0.

John W. Vinson[MVP]

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 

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