Results 1 to 12 of 12
  1. #1
    nemesisswe is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Nov 2021
    Location
    Sweden
    Posts
    17

    Change size of font IF it won't fit inside text box


    Is it possible to use the conditional formatting to see that the text won't "overspill" a line?
    so it shrinks the font size?

    OR

    make an condition that if current data is longer than 20chars then set fontsize 10, longer than 30, size 8 and so on?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Have you tried? That sounds like a very long formula. Build a function that can be called from CF rule.

    I set text for a non-proportional font, limit number of characters in table design and set textbox size to fit longest possible text if I don't want to allow textbox to shrink/grow on report so report page does not change in length.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    nemesisswe is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Nov 2021
    Location
    Sweden
    Posts
    17
    Quote Originally Posted by June7 View Post
    Have you tried?
    Tried?, actually, no, my knowledge don't stretch so far, it took me over 4 hours to get [Platform]="PlayStation 5" to work as an expression condition to change the color.
    And then I already had that code from my trials with libreoffice.

    I only started to use access yesterday, first time ever...

    I was actually thinking about something smaller, since all we actually need is an expression, like: [Title]$char>30 and then let the built-in conditional formatting do the rest.
    But I actually have no idea if there is a code that works like that?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Something like:

    Len([textboxname])>=30

    I just checked CF rule and there is no option for setting font size. Can't use CF for this. Could use VBA but be aware that using VBA to set properties of controls on form affects ALL instances of control, not just current record.
    Last edited by June7; 11-07-2021 at 07:57 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    nemesisswe is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Nov 2021
    Location
    Sweden
    Posts
    17
    dang! I actually just assumed it since it had colors and bold, underlined...

    ok, plan B, is there something called conditional printing? (exist in libreoffice)? cause then I could have 2,3 "title" boxes upon each other, and just show the one with fontsize 12 if letters < 15, and one with fontsize 10 if letters are >15&&<20...

  6. #6
    nemesisswe is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Nov 2021
    Location
    Sweden
    Posts
    17
    surely an conditional show/hide function must exist?

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    is there something called conditional printing?
    in a report there are the onformat and onprint events for each section - so you can put code in those events to change font size. But usually you would use the control can shrink/grow properties to allow for longer text which requires no code at all

    Form controls also have these properties but they are only applied if you print the form

    see this link where pretty much the same question was asked
    https://www.access-programmers.co.uk.../#post-1787940

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    surely an conditional show/hide function must exist?
    no, usual solution is to set the forecolor to the same as the backcolor

  9. #9
    nemesisswe is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Nov 2021
    Location
    Sweden
    Posts
    17
    Quote Originally Posted by Ajax View Post
    no, usual solution is to set the forecolor to the same as the backcolor
    Well, unfortunately doesn't transparent color exist as font color..

    But how about what I wrote in no. 5 here, use 2 similar text boxes, and use something like:


    if Len([Title])>=30 then [textbox1].visible=no && [textbox2].visible=yes

    ..but of course use a valid code (I can't code)

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    set the back color to the same as the section color and don't use transparent. Or set the forecolor to the section color rather than the control backcolor

    With regards your code, learn how access works - it does not work the same as libre

    if Len([Title])>=30 then [textbox1].visible=no && [textbox2].visible=yes

    so you might use

    Code:
    [textbox1].visible=Len([Title])<30
    [textbox2].visible=Len([Title])>=30
    

    or

    Code:
    If Len([Title])>=30 then
        [textbox1].visible=false
        [textbox2].visible=true
    else
        [textbox1].visible=true
        [textbox2].visible=false
    end if
    you decide which way you want to go

    Or you could just make the one textbox wider and hide borders, and/or set justify to centre or right

    or if you want to change font size then code something like

    Code:
    Select Case Len(Title)
        case<30:
            txtBox.fontsize=11
        case <40
            txtbox.fontsize=10
        case <50
            txtbox.fontsize=9
        case else
            txtbox.size=8
    End Select
    or use the cangrow property as already suggested - this only affects the height of the control, not the width

    to find out more google/bing something like 'access vba cangrow' or 'access vba some term or other'. You will find the MS documentation, posts on this and other forums that may or may not be relevant depending on how focussed your search phrase is

  11. #11
    nemesisswe is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Nov 2021
    Location
    Sweden
    Posts
    17
    wow, thx for the information, now I got a starting point!

  12. #12
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Whilst doing this is certainly possible, I would strongly advise against it.
    The code is unnecessarily complex and, in my opinion anyway, the end result can look a compete mess.

    Instead I suggest using a zoom form to display text which is too long to fit in the available space. For example:

    Click image for larger version. 

Name:	MoveForm3_Subform2.PNG 
Views:	11 
Size:	25.9 KB 
ID:	46569

    If you want to see how that was done, please read my article Move Forms & Controls - Mendip Data Systems
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Setting Font size in text box, set to rich text
    By Miles R in forum Programming
    Replies: 5
    Last Post: 09-01-2021, 11:55 AM
  2. Replies: 13
    Last Post: 10-26-2019, 06:06 PM
  3. Replies: 12
    Last Post: 01-12-2019, 06:02 PM
  4. Replies: 3
    Last Post: 07-28-2014, 03:02 PM
  5. Replies: 3
    Last Post: 07-05-2010, 10:46 PM

Tags for this Thread

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