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 |
#1
|
|||
|
|||
Help with code problem on form
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 |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
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. 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. |
#4
|
|||
|
|||
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 .. . 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. |
#5
|
|||
|
|||
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. 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 . .. 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. |
#6
|
|||
|
|||
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 .. . 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 ... 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. |
#7
|
|||
|
|||
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? 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 . .. 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 m... 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. |
#8
|
|||
|
|||
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 .. . 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 ... 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 om... 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. |
#9
|
|||
|
|||
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 . .. 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 m... 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. |
#10
|
|||
|
|||
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 ... 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 om... 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. |
|
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 |