Did an object grow with CanGrow?

shacket

Registered User.
Local time
Today, 15:40
Joined
Dec 19, 2000
Messages
218
I have a report that prints the name and address of a person onto a postcard. I have the CanGrow property set to Yes so that if someone has a long name, it won't get cut off. However, it looks kind of dumb:

Mr. and Mrs. John
Smith

Is there a way, perhaps through the OnPage event, to find out if that field has grown (if the data is too long for one line) and, if so, lower the font size?
 
Asssumedly you know how many characters you can fit in the box before you need to reduce the font size.

Given that you can check the Len() of your input and compare it against the max length to see if you need to reduce the font size.

I believe something like this will do it:

Const MaxCharsForBox = 16
If Len([YourFieldNamesHere]) >MaxCharsForBox Then
Me![MyField].FontSize = 10
End if

I think that should work.

Ian
Ekse

[This message has been edited by Fornatian (edited 08-02-2001).]
 
Thanks. I'll try that.

By the way, if I put that code in the OnPage event, would it adjust each record individually that it prints (i.e. diminish the font size on only those records whose data was too long)?
 
To be honest, I don't do code in reports unless I absolutely have to because I can never remember which On event to put the code in.

But I think it should be OnFormat of your detail.

No promises though.

Ian
 
OK, problem. The number of letters is not relevant because the different letters are different widths. So I can fit 50 'i's in there but only 24 'T's. I need another way to figure out whether the data is too long for the text box.
 
Again assumedly you can determine which letters are wide and which are narrow. Let's make the assumption that all uppercase letters are wide and lowercase letters are narrow. You could do something like:

Dim i as integer
Dim intHowWide as Single
Const MaxCharsForBox = 16

For i = 0 to Len([MyFields])
Select Case Mid([MyField],i,1)
Case "a","b","c","d","e","f" etc
intHowWide = intHowWide + 0.5
Case "A","B","C" etc
intHowWide = intHowWide + 1
Case Else
intHowWide = intHowWide + 1
End Select

Const MaxCharsForBox = 16
If intHowWide >MaxCharsForBox Then
Me![MyField].FontSize = 10
End if

i know it's a bit of a poor answer but it's all i can think of.

Ian

PS. I know that you can use the Chr function to return the character code which would make life easier as you code say:

Case >97 'upper case

for the letter but I only used the above as a demonstration of the theory.


[This message has been edited by Fornatian (edited 08-03-2001).]
 
I figured it out. There is a TextWidth property that answers exactly what I was looking for: how wide is the text with the formatting as it is? It is measured in something called "Twips", which is 1440 twips = 1 inch.

With that in the OnFormat event, I am able to diminish the font size if the TextWidth is too big.

Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom