The Expression you enters contains invalid syntax (if statement)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Norgi
    New Member
    • Apr 2014
    • 2

    The Expression you enters contains invalid syntax (if statement)

    kk so ive been looking at it (and im pretty new to access)
    but i dont know what is wrong with my statement
    plz help

    Code:
    = SiteIncome IIf([LocationsT].[SiteID]=1,
       [Totalincome].[castleblackincome],
          IIf([LocationsT].[SiteID]=2,
                [Totalincome].[Torontoincome],
                   IIf([LocationsT].[SiteID]=3,
                      [Totalincome].[Edmontonincome],
                         "")))
    Last edited by zmbd; Apr 22 '14, 12:18 AM. Reason: [z{added required code tags}{stepped the code for easier reading}]
  • Norgi
    New Member
    • Apr 2014
    • 2

    #2
    im retarded
    sorry for the waste of anyones time
    i just say the = is in the wrong place

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      No big deal
      Typos haunt all of us (^_^)

      In the future, please use the code button to format your posted scripts or formated text.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        You don't mention where you are using this construct.
        I find nested IIF() to be a pain to follow.
        So instead you may want to consider the switch() function

        In a calculated query field you can do something like this:
        Code:
        zs: Nz(
           Switch([people_pk]=6,"six",
                  [people_pk]=7,"seven",
                  [people_pk]=8,"eight"),
           "No Match")
        Here I use the NZ() to act like a case-else

        The same will hold true in a form or report text field, simply replace the "zs:" with an equal-sign.

        So in your case it would appear to be (in the query):

        Code:
        CalcIncome: Nz(
           Switch([LocationsT].[SiteID]=1,[Totalincome].[castleblackincome],
                  [LocationsT].[SiteID]=2,[Totalincome].[Torontoincome],
                  [LocationsT].[SiteID]=3,[Totalincome].[Edmontonincome]),
           0)
        replaceing "CalcIncome :" with "=" for use in a form/report control.
        In this case if your conditions fail, thus returning a null value, I've trapped this, so-to-speak, to return a zero value.

        Comment

        Working...