WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

auto resize a text in a text box

 
   Home -> Office other -> Reports RSS
Next:  IIF in a report Footer  
Author Message
Arlene

External


Since: Nov 18, 2004
Posts: 75



(Msg. 1) Posted: Fri Oct 10, 2008 3:48 pm
Post subject: auto resize a text in a text box
Archived from groups: microsoft>public>access>reports (more info?)

Hi, is there a way to auto resize a text to fill the text box. I want to use
this for a name tag to fill up the text box according to name's length. Thank
you in advance.
Back to top
Login to vote
Marshall Barton

External


Since: Dec 07, 2003
Posts: 1697



(Msg. 2) Posted: Fri Oct 10, 2008 6:53 pm
Post subject: Re: auto resize a text in a text box [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Arlene wrote:

>Hi, is there a way to auto resize a text to fill the text box. I want to use
>this for a name tag to fill up the text box according to name's length. Thank
>you in advance.


What do you mean by "resize"?

If you mean change its FontSize and it fits on one line,
then try something like:

Dim fs As Integer
For fs = 14 To 5 Step -1
If TextWidth(Me.thetextbox) < Me.thetextbox.Width Then
Exit For
End If
Next fs
Me.thetextbox.FontSize = fs

--
Marsh
MVP [MS Access]
Back to top
Login to vote
Nick Thompson

External


Since: Oct 05, 2009
Posts: 1



(Msg. 3) Posted: Mon Oct 05, 2009 4:03 am
Post subject: Trying to do the same thing [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi

Sorry for digging up an old thread but I have the same problem as Arlen. Trying to use the code you've provided, Marsh, but it's not quite working as expected. Can you help?

This is my full code, inc debugging info

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Dim fs As Integer

Debug.Print Text0 & vbCrLf & "Height: " & Text0.Height & " Width: " & Text0.Width & " TextWidth/Height:" & TextWidth(Me.Text0) & "/" & TextHeight(Me.Text0) & " FONT SIZE: " & Me.Text0.FontSize

For fs = 25 To 5 Step -1
Me.Text0.FontSize = fs
If TextWidth(Me.Text0) < Me.Text0.Width Then
Exit For
End If
Next fs

Debug.Print "Height: " & Text0.Height & " Width: " & Text0.Width & " TextWidth/Height:" & TextWidth(Me.Text0) & "/" & TextHeight(Me.Text0) & " FONT SIZE: " & Me.Text0.FontSize & vbCrLf

End Sub


The debugging info this gives me is:

Short
Height: 559 Width: 5265 TextWidth/Height:480/269 FONT SIZE: 4
Height: 559 Width: 5265 TextWidth/Height:480/269 FONT SIZE: 25

Very very very very long indeed
Height: 559 Width: 5265 TextWidth/Height:2818/269 FONT SIZE: 25
Height: 559 Width: 5265 TextWidth/Height:2818/269 FONT SIZE: 25

Quite long text
Height: 559 Width: 5265 TextWidth/Height:1330/269 FONT SIZE: 25
Height: 559 Width: 5265 TextWidth/Height:1330/269 FONT SIZE: 25

(the first line in each section is the value in the text box).

All of the text comes out the same size. I would expect the second value to have resulted in small text, but it gets cropped instead. As you can see, the TextWidth of that text is 2818, which is less than the width of the textbox (5265). But as the text is longer than the text box I'd have expected it to have been higher than 5265.

I've also tried the same code in Report_Page event but I either get text at 25 points or 5 points - nowhere in between.

Thanks in advance if you can help!

Nick



Marshall Barton wrote:

Re: auto resize a text in a text box
10-Oct-08

Arlene wrote:



What do you mean by "resize"?

If you mean change its FontSize and it fits on one line,
then try something like:

Dim fs As Integer
For fs = 14 To 5 Step -1
If TextWidth(Me.thetextbox) < Me.thetextbox.Width Then
Exit For
End If
Next fs
Me.thetextbox.FontSize = fs

--
Marsh
MVP [MS Access]

EggHeadCafe - Software Developer Portal of Choice
Silverlight 2 Beta 2 - Doing Data Part I
http://www.eggheadcafe.com/tutorials/aspnet/5091fa75-2e9b-40d4-88cc-58...a7e83f8
Back to top
Login to vote
Marshall Barton

External


Since: Dec 07, 2003
Posts: 1697



(Msg. 4) Posted: Mon Oct 05, 2009 2:46 pm
Post subject: Re: Trying to do the same thing [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Nick Thompson wrote: [snipped to essentials]
>Trying to use the code you've provided, Marsh, but it's not
>quite working as expected.
>
>Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
> Dim fs As Integer
>
> For fs = 25 To 5 Step -1
> Me.Text0.FontSize = fs
> If TextWidth(Me.Text0) < Me.Text0.Width Then
> Exit For
> End If
> Next fs
>End Sub
>
>All of the text comes out the same size. I would expect the second value to have resulted in small text, but it gets cropped instead. As you can see, the TextWidth of that text is 2818, which is less than the width of the textbox (5265). But as the text is longer than the text box I'd have expected it to have been higher than 5265.


Nothing in that code tells TextWidth what font size to use
so it's always using whatever the report's default font
size. I should be more like:

Dim fs As Integer
For fs = 14 To 5 Step -1
Me.FontSize = fs
If TextWidth(Me.thetextbox) < Me.thetextbox.Width Then
Exit For
End If
Next fs
Me.thetextbox.FontSize = fs

--
Marsh
MVP [MS Access]
Back to top
Login to vote
Display posts from previous:   
       Home -> Office other -> Reports All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
 Office
  Office Other
 Security
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET |
  • IT Support