Text Box with data source of iif statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cwby1966
    New Member
    • Feb 2007
    • 49

    Text Box with data source of iif statement

    I have a text box on a form with the following data source iif statement.
    Code:
    =IIf([leasecnt]=0,"No Leases Entered ",IIf([tbl_leasefllwup].[Form]![fllcnt]=0,"No Items Entered",IIf([tbl_leasefllwup].[Form]![pstd]>"0","Past due Follow-up Items",IIf([tbl_leasefllwup].[Form]![Due]>"0","Follow Up Items to Review","No Review Items"))))
    This text box is to display the proper text accordingly.

    allI keep getting is #Name?
    What am i doing wrong?
    Please help
    Last edited by NeoPa; Oct 14 '08, 08:24 PM. Reason: Please remember to use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32645

    #2
    References must be to the underlying data source or form controls. Referring to specified table fields is not possible.

    You give too little info to be much further help at this time.

    Comment

    • cwby1966
      New Member
      • Feb 2007
      • 49

      #3
      Originally posted by NeoPa
      References must be to the underlying data source or form controls. Referring to specified table fields is not possible.

      You give too little info to be much further help at this time.
      All of the controls in the if statement are form controls they are unbound cont fields

      Comment

      • GazMathias
        Recognized Expert New Member
        • Oct 2008
        • 228

        #4
        Originally posted by cwby1966
        All of the controls in the if statement are form controls they are unbound cont fields
        From what I can gather, you are just trying to write a bit of status text depending on some conditions. If this were me I would write a sub containing a few If and/or Select statements to check all of your conditions and have the form call that sub after it opens / changes. It would write its result to a Label on the form, not a textbox.

        For three reasons really,

        1, It is much easier to read code when it is indented and commented (not only to others but for yourself months/years later).

        2, So that you can debug it in the VB window when you call it (by clicking in the margin next to the sub name, a burgundy dot will be placed there signifying that the next time you run it it will open the VB window and you can step through the code using F8, checking your logic and flow control. Also if you hover over a variable, it will show you its contents (after it has been parsed). You can also type commands directly into the Immediate Window as afurther tool.

        3. Error Handling.

        If all of the controls you are trying to check are on the form, reference them like

        Code:
        Dim somevariable As String
        
        somevariable = Me.SomeControl.Value
        
        If somevariable = "somestatus" then
          Do something
            Else
          Do something else
        End If
        Then update the label like

        Code:
        Me.LabelStatus.Value = somevalue
        Gaz

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32645

          #5
          Good tips Gaz. An article on debugging can be found at Debugging in VBA. To display data in a label use the .Caption property rather than the (non-existent) .Value property. .Caption doesn't appear in the list of label properties you are prompted with, so you will need to type it out in full.

          @OP I will look again in the light of what you've posted, but you obviously haven't put a lot of effort into providing helpful information, so I doubt I'll be in any better position to help when I do. Your choice.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32645

            #6
            Originally posted by cwby1966
            All of the controls in the if statement are form controls they are unbound cont fields
            If [tbl_leasefllwup].[Form]![fllcnt] is a reference to a control on your form then it is an invalid one. This is at least one of your problems.

            No idea what "cont fields" are :S

            Comment

            • GazMathias
              Recognized Expert New Member
              • Oct 2008
              • 228

              #7
              Originally posted by NeoPa
              Caption property rather than the (non-existent) .Value property.
              Oops, my bad. Thank the powers that be for Intellisense!

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32645

                #8
                We try Gaz ;)

                We also make mistakes too of course so no worries :D

                Comment

                Working...