If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#11
|
|||
|
|||
[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. On Wed, 14 Sep 2005 20:01:39 -0700, "Randy" wrote: 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! On Wed, 14 Sep 2005 19:32:25 -0700, "Randy" wrote: Numbers, Format fixed, decimal places 1, Double integer in table I dont know how to do the msgBox test...Randy RuralGuy wrote in message m... Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the MsgBox test? On Wed, 14 Sep 2005 19:12:38 -0700, "Randy" wrote: 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 news:b1lhi15m1fr89im7b7fc0jklql462inm4l@4ax. com... 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. On Wed, 14 Sep 2005 18:51:16 -0700, "Randy" wrote: 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 news:quihi159el28eepchhv1v8rkcjkuebl28p@4a x.com... 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. On Wed, 14 Sep 2005 09:08:50 -0700, "Randy" wrote: 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. |
#12
|
|||
|
|||
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. On Wed, 14 Sep 2005 20:15:19 -0700, "Randy" wrote: [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. On Wed, 14 Sep 2005 20:01:39 -0700, "Randy" wrote: 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! On Wed, 14 Sep 2005 19:32:25 -0700, "Randy" wrote: Numbers, Format fixed, decimal places 1, Double integer in table I dont know how to do the msgBox test...Randy RuralGuy wrote in message om... Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the MsgBox test? On Wed, 14 Sep 2005 19:12:38 -0700, "Randy" wrote: 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 news:b1lhi15m1fr89im7b7fc0jklql462inm4l@4ax .com... 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. On Wed, 14 Sep 2005 18:51:16 -0700, "Randy" wrote: 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 news:quihi159el28eepchhv1v8rkcjkuebl28p@4 ax.com... 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. On Wed, 14 Sep 2005 09:08:50 -0700, "Randy" wrote: 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. |
#13
|
|||
|
|||
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 RuralGuy wrote in message ... 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. On Wed, 14 Sep 2005 20:15:19 -0700, "Randy" wrote: [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. On Wed, 14 Sep 2005 20:01:39 -0700, "Randy" wrote: I get a message of: [FM] is equal to -4.54747350886464E-13 RuralGuy wrote in message m... 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! On Wed, 14 Sep 2005 19:32:25 -0700, "Randy" wrote: Numbers, Format fixed, decimal places 1, Double integer in table I dont know how to do the msgBox test...Randy RuralGuy wrote in message news:rgmhi1lunti8f195pm578hoogmd7p0mg4n@4ax. com... Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the MsgBox test? On Wed, 14 Sep 2005 19:12:38 -0700, "Randy" wrote: 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 news:b1lhi15m1fr89im7b7fc0jklql462inm4l@4a x.com... 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. On Wed, 14 Sep 2005 18:51:16 -0700, "Randy" wrote: 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 news:quihi159el28eepchhv1v8rkcjkuebl28p@ 4ax.com... 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. On Wed, 14 Sep 2005 09:08:50 -0700, "Randy" wrote: 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. |
#14
|
|||
|
|||
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 On Wed, 14 Sep 2005 20:15:19 -0700, "Randy" wrote: [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. On Wed, 14 Sep 2005 20:01:39 -0700, "Randy" wrote: 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! On Wed, 14 Sep 2005 19:32:25 -0700, "Randy" wrote: Numbers, Format fixed, decimal places 1, Double integer in table I dont know how to do the msgBox test...Randy RuralGuy wrote in message om... Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the MsgBox test? On Wed, 14 Sep 2005 19:12:38 -0700, "Randy" wrote: 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 news:b1lhi15m1fr89im7b7fc0jklql462inm4l@4ax .com... 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. On Wed, 14 Sep 2005 18:51:16 -0700, "Randy" wrote: 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 news:quihi159el28eepchhv1v8rkcjkuebl28p@4 ax.com... 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. On Wed, 14 Sep 2005 09:08:50 -0700, "Randy" wrote: 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. |
#15
|
|||
|
|||
You might also want to look at the query/table data directly rather than using
the form. You might see something different. On Wed, 14 Sep 2005 20:35:41 -0700, "Randy" wrote: 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 RuralGuy wrote in message .. . 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. On Wed, 14 Sep 2005 20:15:19 -0700, "Randy" wrote: [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. On Wed, 14 Sep 2005 20:01:39 -0700, "Randy" wrote: I get a message of: [FM] is equal to -4.54747350886464E-13 RuralGuy wrote in message om... 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! On Wed, 14 Sep 2005 19:32:25 -0700, "Randy" wrote: Numbers, Format fixed, decimal places 1, Double integer in table I dont know how to do the msgBox test...Randy RuralGuy wrote in message news:rgmhi1lunti8f195pm578hoogmd7p0mg4n@4ax .com... Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the MsgBox test? On Wed, 14 Sep 2005 19:12:38 -0700, "Randy" wrote: 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 news:b1lhi15m1fr89im7b7fc0jklql462inm4l@4 ax.com... 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. On Wed, 14 Sep 2005 18:51:16 -0700, "Randy" wrote: 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 news:quihi159el28eepchhv1v8rkcjkuebl28p @4ax.com... 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. On Wed, 14 Sep 2005 09:08:50 -0700, "Randy" wrote: 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. |
#16
|
|||
|
|||
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 he http://allenbrowne.com/ser-47.html Especially turning off Name Auto-Correct and doing a decompile and then a compact and repair. On Wed, 14 Sep 2005 20:35:41 -0700, "Randy" wrote: 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 RuralGuy wrote in message .. . 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. On Wed, 14 Sep 2005 20:15:19 -0700, "Randy" wrote: [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. On Wed, 14 Sep 2005 20:01:39 -0700, "Randy" wrote: I get a message of: [FM] is equal to -4.54747350886464E-13 RuralGuy wrote in message om... 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! On Wed, 14 Sep 2005 19:32:25 -0700, "Randy" wrote: Numbers, Format fixed, decimal places 1, Double integer in table I dont know how to do the msgBox test...Randy RuralGuy wrote in message news:rgmhi1lunti8f195pm578hoogmd7p0mg4n@4ax .com... Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the MsgBox test? On Wed, 14 Sep 2005 19:12:38 -0700, "Randy" wrote: 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 news:b1lhi15m1fr89im7b7fc0jklql462inm4l@4 ax.com... 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. On Wed, 14 Sep 2005 18:51:16 -0700, "Randy" wrote: 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 news:quihi159el28eepchhv1v8rkcjkuebl28p @4ax.com... 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. On Wed, 14 Sep 2005 09:08:50 -0700, "Randy" wrote: 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. |
#17
|
|||
|
|||
Truncate as you suggested did the trick. It is working the way i want it
to. Thanks for your help...Randy RuralGuy wrote in message ... 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 On Wed, 14 Sep 2005 20:15:19 -0700, "Randy" wrote: [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. On Wed, 14 Sep 2005 20:01:39 -0700, "Randy" wrote: I get a message of: [FM] is equal to -4.54747350886464E-13 RuralGuy wrote in message m... 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! On Wed, 14 Sep 2005 19:32:25 -0700, "Randy" wrote: Numbers, Format fixed, decimal places 1, Double integer in table I dont know how to do the msgBox test...Randy RuralGuy wrote in message news:rgmhi1lunti8f195pm578hoogmd7p0mg4n@4ax. com... Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the MsgBox test? On Wed, 14 Sep 2005 19:12:38 -0700, "Randy" wrote: 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 news:b1lhi15m1fr89im7b7fc0jklql462inm4l@4a x.com... 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. On Wed, 14 Sep 2005 18:51:16 -0700, "Randy" wrote: 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 news:quihi159el28eepchhv1v8rkcjkuebl28p@ 4ax.com... 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. On Wed, 14 Sep 2005 09:08:50 -0700, "Randy" wrote: 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. |
#18
|
|||
|
|||
Glad I could help.
On Wed, 14 Sep 2005 21:07:00 -0700, "Randy" wrote: Truncate as you suggested did the trick. It is working the way i want it to. Thanks for your help...Randy RuralGuy wrote in message .. . 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 On Wed, 14 Sep 2005 20:15:19 -0700, "Randy" wrote: [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. On Wed, 14 Sep 2005 20:01:39 -0700, "Randy" wrote: I get a message of: [FM] is equal to -4.54747350886464E-13 RuralGuy wrote in message om... 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! On Wed, 14 Sep 2005 19:32:25 -0700, "Randy" wrote: Numbers, Format fixed, decimal places 1, Double integer in table I dont know how to do the msgBox test...Randy RuralGuy wrote in message news:rgmhi1lunti8f195pm578hoogmd7p0mg4n@4ax .com... Got it. What type of fields are [Sample]-[Edible]-[Ined]? Did you try the MsgBox test? On Wed, 14 Sep 2005 19:12:38 -0700, "Randy" wrote: 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 news:b1lhi15m1fr89im7b7fc0jklql462inm4l@4 ax.com... 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. On Wed, 14 Sep 2005 18:51:16 -0700, "Randy" wrote: 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 news:quihi159el28eepchhv1v8rkcjkuebl28p @4ax.com... 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. On Wed, 14 Sep 2005 09:08:50 -0700, "Randy" wrote: 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. |
#19
|
|||
|
|||
On Wed, 14 Sep 2005 20:35:41 -0700, "Randy" wrote:
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] |
#20
|
|||
|
|||
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. On Wed, 14 Sep 2005 22:18:47 -0600, John Vinson wrote: On Wed, 14 Sep 2005 20:35:41 -0700, "Randy" wrote: 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. |
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Intermitant failure to send e-mail in Outlook 2002 | Bob J | General Discussion | 6 | June 29th, 2005 04:47 AM |
error 550 won't deliver | theMooooo | General Discussion | 3 | March 29th, 2005 12:47 PM |
Problem with VBA Code behind form | Tom | Using Forms | 11 | February 21st, 2005 05:42 PM |
Problem with VBA Code behind form | Tom | General Discussion | 11 | February 21st, 2005 05:42 PM |
Excellent Navigation Method! | Bill Mitchell | Using Forms | 3 | December 16th, 2004 01:49 PM |