Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    bjsbrown is offline Novice
    Windows 7 Access 2000
    Join Date
    Oct 2009
    Posts
    21

    Red face Concatenation and IIF statements in report

    Have searched and spent many hours but can't fix - any help appreciated. Use 2000 and vista. Have an address1 field, address2 field, city field, state field, and zipcode field. I can concatenate the city, state and zip field like it needs to be in the report but the problem is most of the records have nothing in the address2 field so i need to eliminate showing a blank line while still concatenating the remainder. If the IIF statement is correct to use, how to write it in relation to the remainder of the address being concatenated.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Post the concantenation line you are currently using, please.

  3. #3
    CGM3 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Atlanta, GA
    Posts
    49
    Off the top of my head:

    Code:
    IIf(IsNull([address2]),"",Trim([address2]))
    If you're using commas or line feeds as delimiters, check to see if Trim([address2]) is more than "" before adding.

    Code:
    IIf(IsNull([address2]),"",IIf(Trim([address2])="","",", " & Trim([address2])))

  4. #4
    bjsbrown is offline Novice
    Windows 7 Access 2000
    Join Date
    Oct 2009
    Posts
    21
    Here you go, Rural Guy
    =Trim([MemCity] & " " & [MemSt] & " " & [MemZip])
    Gives result of Evans GA 30809

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I was looking for how you were contantenating the address1 and address2 fields. Are you adding in CarriageReturns and LineFeeds?

  6. #6
    bjsbrown is offline Novice
    Windows 7 Access 2000
    Join Date
    Oct 2009
    Posts
    21
    I'm not; that's the problem, I guess. I don't know how to write whatever is needed to get rid of the extra line if there is no value on address2. It's been a long time since I tried to do this so am a little rusty. I will say no to carriage returns and line feeds. I also tried what CMG3 suggested but didn't work.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is this in a report? Are you trying to get the address on either three or four lines? Is there anything else on the line with address2?

  8. #8
    bjsbrown is offline Novice
    Windows 7 Access 2000
    Join Date
    Oct 2009
    Posts
    21
    Yes a report to come out as follows:

    John H Smith (Name of Client field)
    2546 Andrews Drive (Address1)
    Suite 450B (Address2)
    Atlanta (City Field) GA (State Field) 30434 (Zip Field)

    If there is no address2 data, go to City, State, Zip rather than leaving an empty line.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If there is nothing else on the line horizontally and the Detail Section is set to CanShrink then you can manipulate the .Visible property of the control in the Print Event of the Detail Section.
    Code:
    If Len(Me.Address2 & "") = 0 Then
       Me.Address2.Visible = False
    Else
       Me.Address2.Visible = True
    End If

  10. #10
    bjsbrown is offline Novice
    Windows 7 Access 2000
    Join Date
    Oct 2009
    Posts
    21
    Haven't been able to get to work yet. Does it go in the query or report?

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It goes in the Print Event of the Detail Section of the Report.

  12. #12
    bjsbrown is offline Novice
    Windows 7 Access 2000
    Join Date
    Oct 2009
    Posts
    21
    Received the following: The expression on print you entered as the event property setting produced the following characher: Invalid character.

    I've tried playing around with it but can't get to work.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did you press the "..." button and put in the code? Post what you have here so we can look at it.

  14. #14
    bjsbrown is offline Novice
    Windows 7 Access 2000
    Join Date
    Oct 2009
    Posts
    21
    Yes to question- I just copied and pasted

    If Len(Me.Address2 & "") = 0 Then
    Me.Address2.Visible = False
    Else
    Me.Address2.Visible = True
    End If
    Private Sub GroupHeader1_Print(Cancel As Integer, PrintCount As Integer)
    End Sub

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The code needs to be in the Section where the control is located. Is your control in the GroupHeader1? It *must* also be AFTER Private and BEFORE End Sub. You put everything before Private.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query for IIF statements
    By SpotoR1 in forum Queries
    Replies: 2
    Last Post: 08-26-2009, 06:57 AM
  2. IIF Statements
    By JDA2005 in forum Queries
    Replies: 8
    Last Post: 07-07-2009, 04:24 PM
  3. Concatenation Urgent Help
    By Shoaib in forum Queries
    Replies: 0
    Last Post: 04-23-2009, 11:02 PM
  4. If statements
    By Ezeecopy in forum Access
    Replies: 0
    Last Post: 03-24-2009, 04:54 AM
  5. Concatenation, nested IIF functions
    By krymer in forum Queries
    Replies: 2
    Last Post: 10-20-2008, 07:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums