Determining String Length in Inches or Twips

G

Guest

Hi all,

I've searched everywhere and I can't find an answer, so I'm posting here.
I'm sure someone can point me in the right direction.

I'm trying to set the column width of a 2-column combo box. I'm doing this
at Form_Load as I don't know ahead of time the column size I'll need.

I'm using a query as the source for the combo box. I want the firts column
to only be as wide as the longest entry in the column.

I'm using a Max(Len(...)) select statement to get the maximum string length
in the column. And I know the font name, size of the combo box.

That's where I'm stuck. I need to find a way to convert that information
into inches or twips, and I can't figure out how. If I can get this work,
I'm going to be using it all over the place.

Any suggestions? I'll appreciate it.

Thanks,
Jay
 
D

Dirk Goldgar

Jay said:
Hi all,

I've searched everywhere and I can't find an answer, so I'm posting
here. I'm sure someone can point me in the right direction.

I'm trying to set the column width of a 2-column combo box. I'm
doing this at Form_Load as I don't know ahead of time the column size
I'll need.

I'm using a query as the source for the combo box. I want the firts
column to only be as wide as the longest entry in the column.

I'm using a Max(Len(...)) select statement to get the maximum string
length in the column. And I know the font name, size of the combo
box.

That's where I'm stuck. I need to find a way to convert that
information into inches or twips, and I can't figure out how. If I
can get this work, I'm going to be using it all over the place.

Any suggestions? I'll appreciate it.

You might have a look at this:

http://www.lebans.com/textwidth-height.htm

<quote>
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.
</quote>
 
G

Guest

There are 1440 twips per inch. If you set a column width in VBA, you will
have t use twips. You say you know the font size and the length of the
longest string in the results. You will have to experiment with an average
number of twips per character and, perhaps, add a few to be save. Most fonts
are proportional, meaning the letter I is narrower than the letter W, but you
can use an average number of twips per character based on the font and font
size. The length of the longest string will tell you the number of
characters to use, so multiply that by the average twips per character.
 
D

Dirk Goldgar

Jay said:
Dirk,

Thanks so much for the link. I manipulated the existing code to get
what I wanted... and then I found this link:

<a
href="http://www.lebans.com/listboxcolumnresize.htm">http://www.lebans.c
om/listboxcolumnresize.htm said:
Haven't got it doing what I want yet, but I thought I'd pass it on.
The demos do what I'm hoping to achieve.

Thought you'd like this link.

Thanks for posting. I should have looked hard for a more specific
solution from Stephen's site. For anything to do with extending the
Access UI, that's the first place to look.
 
G

Guest

To future users reading this post:

If you use Lebans column width code, you MUST set the column width of the
control to a default value.

I had a hell of a time trying to determine why my program was crashing, and
that was the cause. I had left the widths value blank, incorrectly assuming
the code would take care of it. It does not.

Hope it helps.

Jay
 

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