Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reduce the Fontsize if to large for text box 1

Status
Not open for further replies.

DustDevil1980

Programmer
Oct 14, 2003
14
US
I have a report with a very specific (static) layout. In some fields, the data varies from just a few words to an entire paragraph. What I want to do is decrease the fontsize to make it all fit. Is there a way to detect if the data moves to the next line or the "can grow" event to reduce the font size? I thought I was on to something with the TextWidth property, but the results seemed to be random. This problem is similar to thread 702-558039, however the user has no control over changing the fontsize when entering the data in the form.
 
You could use the following. It will reduce the fontsize from 8, first to 7, then to 6 depending on the number of characters.

Just test the maximum number of characters your text box can accomodate at the required font size, then adjust the values below accordingly.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Len([FieldNameA]) > 32 And Len([PipeDrawingNo]) < 36 Then
Me!txtFieldNameA.FontSize = 7
ElseIf Len([FieldNameA]) >= 36 Then
Me!txtFieldNameA.FontSize = 6
Else
Me!txtFieldNameA.FontSize = 8
End If
End Sub

The above works on the On Format event of the 'Details' section. If you use it in another section change the Sub name to match.

SqlJunior
 

Sorry, didn't modify all the field names.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Len([FieldNameA]) > 32 And Len([FieldNameA]) < 36 Then
Me!txtFieldNameA.FontSize = 7
ElseIf Len([FieldNameA]) >= 36 Then
Me!txtFieldNameA.FontSize = 6
Else
Me!txtFieldNameA.FontSize = 8
End If
End Sub

SqlJunior
 
The only problem with doing it that way is I'm using the Ariel font. So if I have ten (10) &quot;W&quot;'s its going to max out as opposed to having ten (10) &quot;I&quot;'s. The text box is three (3) inches long. Is there a way to to say if the value is longer than three (3) inches, then decrese the fontsize?
 
Oh... BTW, I'm using Access 2k on Windows 2k. It seems to me that the answer lies somewhere with the TextWidth property, But as I said ealier, it seemed to give random results. If this is the direction, I can post the code and hopefully figure out why the results are random.
 
Thanks Duane! it works great. This is the second time you've saved my butt. Star for you.
 
Stephen did all the work. I just know where to go [bigsmile].

Duane
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top