422,949 Members | 1,000 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,949 IT Pros & Developers. It's quick & easy.

shrink to fit like excel

P: 2
can someone help me...

this is my problem...

I am generating a report where in i have a textbox with a fix length.. then i want that any datas that will be called out to that textbox will fit into the text box without resizing or editing the textbox...
(hence.. like shrink to fit property of a cell in MS Excel )..

please please please,,,....
thanks in advance...
Sep 13 '08 #1
Share this Question
Share on Google+
5 Replies


puppydogbuddy
Expert 100+
P: 1,923
1. Place the report in design view
2. higlight the textbox
3. invoke the property sheet for that textbox
4. set the "can Grow" and "can Shrink" properties to yes
Sep 13 '08 #2

nico5038
Expert 2.5K+
P: 3,072
Access has no "shrink to fit property" for a text box.
All you can do is calculate the max length (in general 255 characters) and see or you can set the font size property from 8 to e.g. 6 to have the max text fit the text box e.g. when more than 150 characters are found.

Nic;o)
Sep 13 '08 #3

P: 2
Thanks nico5038...

Another is that...
I tried to do that by using the TEXTHEIGHT command during the print or preview in the report but an error occurred...

It seam that access don't know this command..
Can show me how to do that??
Sep 14 '08 #4

nico5038
Expert 2.5K+
P: 3,072
It's not the "Text height", but the "Font Size" property you need to manipulate in the OnFormat event like:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.  
  3. If Len(Me.QuerySQL) > 150 Then
  4.   Me.QuerySQL.FontSize = 6
  5. Else
  6.   Me.QuerySQL.FontSize = 10
  7. End If
  8.  
  9. End Sub
  10.  
Nic;o)
Sep 14 '08 #5

P: 1
copy these codes in a report details properties and on print event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
  2. Dim ctl As Control, strText As Variant, strName As String
  3. ' This routine uses the TextWidth methods to determine the maximum size
  4. ' of font possible to ensure a text string is printed in full in the
  5. ' report's current font without loosing any characters.
  6.  
  7.     Me.ScaleMode = 1 ' set all measurments to twips
  8.  
  9.     For Each ctl In Me.Detail.Controls
  10.  
  11.         If ctl.ControlType = acTextBox Then
  12.  
  13.         strName = ctl.Name
  14.  
  15.             If Nz(ctl.Tag, "") = "" Then
  16.                 ctl.Tag = ctl.FontSize
  17.             End If
  18.  
  19.  
  20.         ' set the control's fontsize to a suitable large size to begin with
  21.             ctl.FontSize = ctl.Tag
  22.  
  23.         ' make sure the report font size is equal to the control's fontsize.
  24.             Me.FontSize = ctl.FontSize
  25.  
  26.         ' grab the text from the control
  27.             strText = ctl.Value
  28.  
  29.         ' evaluate the Loop until the text fits the Width of the box less 24%. Do this
  30.         ' by reducing the font size incrementally and re-testing the Loop's criteria.
  31.            If Len(strText) > 0 Then
  32.             Do Until TextWidth(strText) < ctl.Width '- (ctl.Width * 0.26)
  33.                 ctl.FontSize = ctl.FontSize - 1
  34.                 ' reset the report's font size so the TextWidth function will
  35.                 ' continue to track the reducing font size correctly.
  36.                 Me.FontSize = ctl.FontSize
  37.             Loop
  38.  
  39.         ' now evaluate for the height of the text to make sure it fits vertically
  40.             Do Until TextHeight(strText) < ctl.Height - (ctl.Height * 0.26)
  41.                 ctl.FontSize = ctl.FontSize - 1
  42.                 ' reset the report's font size so the TextHeight function will
  43.                 ' continue to track the reducing font size correctly.
  44.                 Me.FontSize = ctl.FontSize
  45.             Loop
  46.  
  47.         End If
  48.         End If
  49.  
  50.     Next ctl
  51. End Sub
May 13 '18 #6

Post your reply

Sign in to post your reply or Sign up for a free account.