Add info from another field if present field is empty

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • glat
    New Member
    • Dec 2016
    • 62

    Add info from another field if present field is empty

    I would like to have a field in my report whereby if one field is empty, information from another field is inserted as it has to be either one or the other.

    I have tried
    Code:
    =IIf([RefNo] Is Null,[AdminRef])
    All it seems to do is add in the AdminRef. Any help much appreciated. I'm sure I've done this before but cannot find or remember how!
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    #2
    What you have done is told it what to do if RefNo is Null.
    You haven't told it what to do if there is a valid RefNo.

    Code:
     IIf(IsNull([RefNo]), [AdminRef],[RefNo])
    Phil

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32663

      #3
      Or, more simply, :
      Code:
      Nz([RefNo]), [AdminRef])

      Comment

      • glat
        New Member
        • Dec 2016
        • 62

        #4
        Phil, can more than one field be added or is it limited to two?

        Comment

        • PhilOfWalton
          Recognized Expert Top Contributor
          • Mar 2016
          • 1430

          #5
          Yes, but you're not helping yourself by not stating whether this is a calculated field on your report, or whether it is the underlying query.

          What specifically do you want to do?

          Phil

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32663

            #6
            ... and with fifty posts now you should be beyond half-considered posts that waste time Glat.

            If you have multiple fields you want to present in the order of whichever is come across first shows, then with fields [A], [B], [C] & [D] you would use :
            Code:
            Nz([A],Nz([B],Nz([C],[D])))

            Comment

            • glat
              New Member
              • Dec 2016
              • 62

              #7
              Phil it is in an unbound text box in the report. It is not calculated.

              Comment

              • glat
                New Member
                • Dec 2016
                • 62

                #8
                Sorry NeoPa.

                I tried your Nz option however all I kept getting was #Type in my text box.

                Comment

                • PhilOfWalton
                  Recognized Expert Top Contributor
                  • Mar 2016
                  • 1430

                  #9
                  Well, if it's not bound to a field in the report's underlying query, and it's not calculated, where is it getting any information from????

                  You have not answered my question "What specifically do you want to do?"

                  Phil

                  Comment

                  • glat
                    New Member
                    • Dec 2016
                    • 62

                    #10
                    The report is based on a query of archived files. Different files have different references and file names; TenantRef, AdminRef; FileDesc, AdminName. I am trying to have all the file references in one text box and all the file names in another text box so the report can fit on a landscape A4 page.

                    Comment

                    • PhilOfWalton
                      Recognized Expert Top Contributor
                      • Mar 2016
                      • 1430

                      #11
                      OK, Glat

                      Can you post the SQL for the report's RecordSource

                      Phil

                      Comment

                      • glat
                        New Member
                        • Dec 2016
                        • 62

                        #12
                        Hi Phil,its
                        Code:
                        SELECT [Archived Files].TenantRef, [Archived Files].From, [Archived Files].To, [Archived Files].Volumes, [Archived Files].FileNo, [Archived Files].Comments, [Archived Files].FileType, Property.PropertyRef, [Archived Files].Destroyed, Property.Town, Tenant.Company, Property.AddressLine1, Property.AddressLine2, Property.AddressLine3, Property.AddressLine4, Property.PostCode, Admin.AdminName, Admin.AdminRef, [Archived Files].FileDescription, [File List].FileListName, [Archived Files].Address, [Archived Files].Town, [File List].Ref
                        FROM [File List] RIGHT JOIN (Property RIGHT JOIN (Admin RIGHT JOIN (Tenant RIGHT JOIN [Archived Files] ON Tenant.TenantID = [Archived Files].TenantID) ON Admin.AdminRefID = [Archived Files].AdminRefID) ON Property.PropertyID = [Archived Files].PropertyID) ON [File List].FirstListNameID = [Archived Files].FileListID
                        ORDER BY [Archived Files].FileNo;

                        Comment

                        • PhilOfWalton
                          Recognized Expert Top Contributor
                          • Mar 2016
                          • 1430

                          #13
                          We're getting there very, very slowly.

                          Now all you need to tell me is what you want to see in your text box.

                          I think there are 2 options

                          1) "ABCDEF, HIJK, LMNOPQR" where ABCDEF represents TenantRef, HIJK represents AdminRef and LMNOPQR represents PropertyRef

                          2) If TenantRef is Null, Show AdminRef, but if both TenantRef and AdminRef are null, Show PropertyRef.

                          Am I close?

                          Phil

                          Comment

                          • glat
                            New Member
                            • Dec 2016
                            • 62

                            #14
                            Phil, yes you are correct: if the TenantRef is Null, show FileListID, if both are Null then show AdminRef. The PropertyRef is a text box on its own.

                            Comment

                            • PhilOfWalton
                              Recognized Expert Top Contributor
                              • Mar 2016
                              • 1430

                              #15
                              We've got there !!!!!!!

                              So in your SQL, before the word "FROM" add

                              Code:
                              IIf(Not IsNull(TenantRef), TenantRef, IIf(Not IsNull(FileListID), FileListID, Nz(AdminRef)))) AS Ref
                              Phil

                              Comment

                              Working...