Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access VBA - automatically fit size of label to text

Hi

I ahve a report where labels are automatically populated with data and centred. My only problem is
that sometimes the text is too long for the label so a portion of it gets hidden. What VBA code would I use to automatically size the label to fit whatever text is in it.

Thanks
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

have you tried setting the property Can Grow and Can Shrink to Yes?
Avatar of Murray Brown

ASKER

Hi

I can't ssem to find that property in my label. Pity they aren't in alphebetical order
looked at that link and can't see what you mean
download the file TextHeightWidth.zip from the link and see if you can apply the method used in the sampledb
That example is pretty complex. Surely Microsoft have a simpler way to do something so obviously necessary!
here is what you can do..

check the length of the caption (how many characters will fit in the Label using the default font size)
then do this

assuming the max number of characters that will fit using the default font that you have is 25

select case Len(me.labelx.caption)
      case 26-28
           me.labelx.fontsize=10


end select

something like that


can you upload your db...




   



end select
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much
To anyone who reads this post: I found a far more workable solution to my initial question. I stretched the label manually to the width of the report and then set the TextAlign property to "Centre"