Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Evansville, Indiana, USA
    Posts
    132
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want to display two fields together in a text box from my table. I can get it to show one of them but not two fields.

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Depends what is in the 2 fields as to exactly how you do it.
    You need to have it as a calculated field in the query or in the text box on the form.
    If the fields are text then you can concatenate the fields together in one text box

    =[Field1] & [Field2]

    If you wanted a comma between them it would be

    =[Field1] & "," & [Field2]

    If you need more help we would need an example of the content of the fields being combined.
    Andrew

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post
    A good trick is to use + intead of & if you dont want the bit on the other side of the + to show if one side is null.

    eg -

    ="Phone : " + [Phone]

    will only show the text "Phone :" if there is a phone number.

    Going even further, you can use this when displaying an address line in a text box. For example –

    [Address_2] + vbCRLF + [Address_State] + “ “ + [Address_Postcode]

    In this example a line feed (expressed as the intrinsic VBA constant vbCRLF – short for Carriage Return Line Feed) occurs after the Address_2, but only if it is not null, so that a blank line is not left before the State and then, if there is no State, a blank space is not left on the line before the postcode.

    If you are using this in a report, then using the can grow and can shrink properties of the text box can then be used to automatically adjust the height.

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    I just have one thing to add to this.

    It is quite common to get an error message (circular reference) when you do this, if you do it a particular way.

    Suppose I had Lastname on a form, then decided I will display [lastname] & ", " & [firstname] instead.

    You could change the Control Source of the control on the form to:
    =[lastname] & ", " & [firstname]

    And then you will get an error.

    The problem is that when you add [lastname] to a form the Name of the control is Lastname as well as its Control Source. So when you change its Control Source to something that refers to Lastname you need to change the name as well. Otherwise you get the circular reference error.

    An alternative way of doing it that avoid the problem is to put the calculation into the query behind the form e.g.

    Code:
    FullName: [lastname] & ", " & [firstname]
    then set the Control Source to FullName .
    Regards
    John



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •