hiding field in form if null and give msgbox if not null

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rodfuentes
    New Member
    • Nov 2013
    • 8

    hiding field in form if null and give msgbox if not null

    Good day,
    I have a form (CSearch) to input data and search for records in a query and displays it on a subform (CAff) once a search button is clicked.

    I have a current event on the subform that check if the field "CONTRACTSTATUS " is "Expired" and if so gives a message box saying "This contract is expired"

    This works when the main form has been loaded already, but whenever I re-open the form I get error 2424 "The expression you entered..."

    Can you help me? Here is the code I'm using:
    Code:
    Private Sub Form_Current()
    If Me.NewRecord Then
    Me!CONTRACTSTATUS.Visible = True
    End If
    If Me.CONTRACTSTATUS.Value = "EXPIRED" Then
    MsgBox ("This contract is expired")
    Else
    Me!CONTRACTSTATUS.Visible = False
    Exit Sub
    End If
    End Sub
    Last edited by NeoPa; Nov 1 '13, 03:53 PM. Reason: Please use the [CODE] tags when posting code.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Please could you include the full error message and the number of the line of code wher it occurs.

    Comment

    • rodfuentes
      New Member
      • Nov 2013
      • 8

      #3
      Run-time error '2424':

      "The expression you entered has a field, control, or property name that toolbox can't find"

      And when I click on Debug, line # 5 is highlighted.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Thank you.

        I expect that means that the subform is using a recordset that is non-updatable. In such a case, when the main form has not yet been used to specify the search, there are no records in the subform at all. As it's not updatable there is not even any possibility of it being at the New Record position. From here Me.CONTRACTSTAT US.Value has no meaning as there is no current record from which it can take context.

        In short, your code needs first to check if there is a current record before it tries to refer to it.

        I hope that helps, and I'm a little confused that, in such a scenario, it would even trigger the Current event. Check out that idea anyway and see what you find.

        Comment

        Working...