Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24

    Blank fields in a report

    I have an address book which can have an empty field. When I run a report include the address i don't want to have the blank space appear on the report. I have managed to this on screen but as soon as i go to print preview it puts the spaces back in??

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Try using this function to produce a calculated single address text field with CR between the elements for use on a report.

    Code:
    Public Function CanShrinkLines(ParamArray arrLines())
        ' Pass this function the lines to be combined
        ' For example: strAddress =
        ' CanShrinkLines(Name, Address1, Address2, City, St, Zip)
        Dim x     As Integer, strLine As String
        For x = 0 To UBound(arrLines)
            If Not IsNull(arrLines(x)) And arrLines(x) <> "" Then
                strLine = strLine & arrLines(x) & vbCrLf
            End If
        Next
        CanShrinkLines = strLine
    End Function
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24
    That's way beyond my skills!! There must be a reason why it is doing it on screen but not whe converting to print preview??

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Cut and paste is beyond you ?

    Click on the file bar and select Create, then Module.
    Paste the code exactly as above. Click save and close the VBA editor. Save the module with a name like modBasFunctions.

    In your reports query create a new field exactly as per below, substituting your field names
    Code:
    strCompactAdd: CanShrinkLines(YourAddrField1, YourAddrField2, YourAddrField3, YourAddrField4, YourAddrField5)
    
    
    In your report add the single field strCompactAdd as the control source for your address box.

    The reason the on screen report is different is because by default the report preview form shrinks/removes "white space" as it doesn't have to do the actual printed page formatting.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24
    What do I need to remove from the code? Sorry but only been playing with access for a short while, but this is quite an important problem!

  6. #6
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24
    I get "undefined function "canshrinklines" in expression". Must be doing something wrong

  7. #7
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Have you saved the code module? What did you call it?
    Can you copy and paste up the exact code from your database please
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24
    Public Function canshrinklines(ParamArray arrLines())
    ' Pass this function the lines to be combined
    ' For example: strAddress =
    ' CanShrinkLines(Name, Address1, Address2, City, St, Zip)
    Dim x As Integer, strLine As String
    For x = 0 To UBound(arrLines)
    If Not IsNull(arrLines(x)) And arrLines(x) <> "" Then
    strLine = strLine & arrLines(x) & vbCrLf
    End If
    Next
    canshrinklines = strLine
    End Function


    the fields i am trying to join are ADDRESS2,ADDRESS3,TOWN,COUNTY,PC




    Actually ended up saving as anshrinklines
    Last edited by sugr74; 11-09-2018 at 08:24 AM. Reason: addition

  9. #9
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by sugr74 View Post
    Actually ended up saving as anshrinklines
    This is the problem - the module can't be called the same as any of the functions in the database. Rename the module
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24
    I will try tomorrow, so the code is correct then?

  11. #11
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by sugr74 View Post
    I will try tomorrow, so the code is correct then?
    It looks ok to me !

    Once you have renamed the module you can test it really easily in the immediate window (Press ctrl + g in the vba window to make it visible)
    Type the following in and press return
    Code:
    ? canshrinklines("Big Town Industries",Null,"","Diagone Alley",Null,"Smallville")
    And you should get
    Code:
    ? canshrinklines("Big Town Industries",Null,"","Diagone Alley",Null,"Smallville")
    Big Town Industries
    Diagone Alley
    Smallville
    Which as you can see has no blank lines with either a null value or empty string "" passed in as values.

    The ? means print the result so

    ?date()
    09/11/2018
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  12. #12
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24
    Thank you so much for your help I will definitely try this tomorrow hopefully!

  13. #13
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24
    I must be doing something wrong as it hasn't worked. I put strCompactAdd in as the control sauce for the address 2 field on the report and the result i get in #name? and still a gap

  14. #14
    sugr74 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2018
    Posts
    24
    I must be doing something wrong as it hasn't worked. I put strCompactAdd in as the control sauce for the address 2 field on the report and the result i get in #name? and still a gap.

    It's only producing the first field that is not null.

  15. #15
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    What happens if you run the test in the immediate window - does that work ?

    Please paste up how you are creating your strCompactAdd in the query.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Blank space between fields in report header
    By cebrower in forum Reports
    Replies: 3
    Last Post: 09-18-2018, 09:48 AM
  2. Replies: 1
    Last Post: 01-31-2018, 04:06 PM
  3. Generate report with blank linked table fields
    By e-support in forum Reports
    Replies: 14
    Last Post: 01-06-2017, 04:11 PM
  4. Border not appearing on blank fields - Report
    By jmitchelldueck in forum Reports
    Replies: 1
    Last Post: 08-26-2015, 08:15 AM
  5. Replies: 2
    Last Post: 02-03-2011, 12:41 PM

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