AutoSize label

O

Onno Willems

Hi,

Is there any way to resize a label (from code) so it's just wide enough to
fit the string i've just put in it?

I have a label with a not-transparent background, which is on top of a
rectangle.Something like this:
--- MyLabel -------------
The text in the label is dynamic (depends on the record) and set from VBA
code. It can vary in length. I need a way to set the width of "MyLabel" so
it's just wide enough to fit its contents. Stupid as it may be, I can not
find a way to do this? (in VB there seem to be a AutoSize field for labels,
but not in VBA for Access? I even found an MSDN article about setting
AutoSize properties for labels in VBA code in Excel, but in Access this
property seems missing.)

Is there any other way to determine how wide a string would be if printed in
a certain font on a form, and then adjust the width of the label to that
width (without switching to design mode)?

Thanks,
Onno
The Netherlands
 
S

Stephen Lebans

See:
http://www.lebans.com/textwidth-height.htm
TextHeightWidth.zip is a replacement for the Report object's TextWidth
and TextHeight methods. It is multiline aware and can work in both
Report and Form views. Includes a sample report to show you how to
autosize individual controls with different formatting on the same line
to simulate RTF style text.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
O

Onno Willems

Thanks! I will look into this tonight!

May I add that you have a great website! Very usefull stuff.

Thanks again,

Onno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top