AfterUpdate Event - runtime 2465 can't find field "|" referred to in your expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kcdoell
    New Member
    • Dec 2007
    • 230

    AfterUpdate Event - runtime 2465 can't find field "|" referred to in your expression

    Hello:

    I have the following afterupdate event:

    [code=vb] Private Sub GWP_AfterUpdate ()
    'Updates the Total calculation in the control "SumGWP" on the quick reference
    'table that is located on the form

    With Me![SumGWP]
    DoCmd.Requery

    End With
    End Sub [/code]

    This worked perfectly. Then I applied code to various objects so that a new record could not be written unless certain conditions existed. In the case of my object "GWP", the value has to greater than 0:

    [code=vb]'Make sure required fields are filled out first

    Dim frm As Form
    Set frm = Forms!Forecast

    If IsNull(frm![Policy_Type]) Or IsNull(frm![Insured_Name]) _
    Or IsNull(frm![LOB]) Or Nz([GWP], 0) = 0 Or Nz([NWP], 0) = 0 _
    Or IsNull(frm![Binding_Percent age]) Then

    If IsNull(frm![Policy_Type]) Then MsgBox "Please select a Policy Type from" & _
    " the list, thank you", 64, "Select a Policy Type"

    If IsNull(frm![Insured_Name]) Then MsgBox "Please indicate who the Insured" & _
    " is, thank you", 64, "Select an Insured"

    If IsNull(frm![LOB]) Then MsgBox "Please choose a LOB from the" & _
    " list, thank you", 64, "Select an LOB"

    If Nz([GWP], 0) = 0 Then MsgBox "Please input a GWP value for the" & _
    " record, thank you", 64, "Input a GWP Value"

    If Nz([NWP], 0) = 0 Then MsgBox "Please input a NWP value for the" & _
    " record, thank you", 64, "Input a NWP Value"

    If IsNull(frm![Binding_Percent age]) Then MsgBox "Please choose a Binding Percentage from" & _
    " the list, thank you", 64, "Select a Binding Percentage"

    Cancel = True
    Else: Cancel = False
    End If

    'If all req fields are populated then proceed to write the record to the forecast table.[/code]

    My problem is that if GWP is 0, I get the error message. That is what I wanted to happen but when I input a value greater than 0 and tab into my next object "NWP", I get the following error"

    [code=text]runtime 2465 can't find field "|" referred to in your expression[/code]

    The debug window focuses on the
    [code=vb]With Me![SumGWP]
    DoCmd.Requery
    End With
    End Sub [/code]

    Highlighting the DoCmd.Requery….

    I have been doing a lot of research on the Internet but can not find a solution. Does anybody understand what my issue could be? During my research it indicated that this message could mean that it can not find the object, but that was not an issue before I put in the required field error messages.

    Any ideas would be helpful.

    Thanks,

    Keith.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi Keith. Can't see any obvious cause for the error in the code as posted. Having said that you are mixing the syntax for the requery a little - you don't need the With or the DoCmd. The syntax is just
    [code=vb]Private Sub GWP_AfterUpdate ()
    Me![SumGWP].Requery
    End Sub [/code]
    The other checking lines don't explain why you should be getting an error. If you find you are still getting the error after simplifying the requery line as above, could you post the calculation you use for your SumGWP field that is being requeried? It may be that there is something wrong there instead.

    -Stewart

    Comment

    • kcdoell
      New Member
      • Dec 2007
      • 230

      #3
      Originally posted by Stewart Ross Inverness
      Hi Keith. Can't see any obvious cause for the error in the code as posted. Having said that you are mixing the syntax for the requery a little - you don't need the With or the DoCmd.......... ........
      Stewart:

      I just got back and thanks for the reply. I am going to probe a little further trying your suggestion and get back to you........

      Comment

      • kcdoell
        New Member
        • Dec 2007
        • 230

        #4
        Stewart:

        Simplifying the requery coding as you suggested seems to have worked. I now can not recreate the error. This was the first time I wrote that kind of code and it did work before I proceed with other VB coding. I am always interested in streamlining how I write stuff but I have learned all by doing and none by formal training.

        Thanks, I would not have figured it out without your help.

        For kicks my code for the SUMGWP was the following:

        [Code=vb] =DSum("[GWP]","ReQryForecas t","Val([Binding_Percent age]) >= 75") [/code]

        This I placed in the control source property of my text box control….

        Thanks again,

        Keith.

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          For doing this one simple thing, using the With construct was really overkill, and Stewart's suggestion was spot on, as always. But if you needed to use the With because you were also doing other things, the proper syntax would have been

          [code=vb] Private Sub GWP_AfterUpdate ()
          With Me![SumGWP]
          .Requery
          End With
          End Sub [/code]

          omitting the DoCmd.

          Linq ;0)>

          Comment

          Working...