SteveL13
asked on
Expand/shrink width of text field on a report
Is there a way to expand (or shrink) the WIDTH of a text field on a report based on the width of the total characters in the field?
control.width = Len(control) * 100
Play with numbers till it works?
566 twips = 10mm
Play with numbers till it works?
566 twips = 10mm
You can do this but it is never perfect.
For example this is 25 characters:
iiiiiiiiiiiiiiiiiiiiiiiii
...but so is this:
WWWWWWWWWWWWWWWWWWWWWWWWW
...so how wide should the textbox be?
;-)
You can use a "0" as the "Average Character" (This is what MS uses when setting column widths), but again, this will never be perfect.
If this is a report, then it might be easier to simply set the "Can Grow" property of the textbox to "Yes", ...and simply let the text wrap.
Then the text will *always* fit
Then no code or experimentation would be needed...
To be clear, I am not trying to knock the other Expert's suggestions, it's that just for me, I like to use the built in functionality first, before reaching for a solution that needs all that code or any experimentation...
"Keep It Simple"
But again, to be fair, their posts do address your question as posted...
;-)
JeffCoachman
For example this is 25 characters:
iiiiiiiiiiiiiiiiiiiiiiiii
...but so is this:
WWWWWWWWWWWWWWWWWWWWWWWWW
...so how wide should the textbox be?
;-)
You can use a "0" as the "Average Character" (This is what MS uses when setting column widths), but again, this will never be perfect.
If this is a report, then it might be easier to simply set the "Can Grow" property of the textbox to "Yes", ...and simply let the text wrap.
Then the text will *always* fit
Then no code or experimentation would be needed...
To be clear, I am not trying to knock the other Expert's suggestions, it's that just for me, I like to use the built in functionality first, before reaching for a solution that needs all that code or any experimentation...
"Keep It Simple"
But again, to be fair, their posts do address your question as posted...
;-)
JeffCoachman
ASKER
To all:
This isn't working but I may be doing something wrong. I'm sending a sample database. If you run the report you'll see two records. What I need to have happen is have the 2nd field adjust itself to the number of characters in the field. Then I need the last label field, (Label1), to move over next to the adjusted text field. Make sense?
TestFieldWidth.accdb
This isn't working but I may be doing something wrong. I'm sending a sample database. If you run the report you'll see two records. What I need to have happen is have the 2nd field adjust itself to the number of characters in the field. Then I need the last label field, (Label1), to move over next to the adjusted text field. Make sense?
TestFieldWidth.accdb
change the CAN GROW property to true
it will grow downwards but it will do what you need done
see how it works with the attached database
TestFieldWidth.accdb
it will grow downwards but it will do what you need done
see how it works with the attached database
TestFieldWidth.accdb
esskayb2d,
<change the CAN GROW property to true>
That is what I suggested in:
https://www.experts-exchange.com/questions/27596187/Expand-shrink-width-of-text-field-on-a-report.html?anchorAnswerId=37624480#a37624480
JeffCoachman
<change the CAN GROW property to true>
That is what I suggested in:
https://www.experts-exchange.com/questions/27596187/Expand-shrink-width-of-text-field-on-a-report.html?anchorAnswerId=37624480#a37624480
JeffCoachman
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is working out nicely...
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.Text4 = Me.Label0.Caption & " " & Me.Text2 & " " & Me.Label1.Caption
End Sub
But now I have one more question... What if I need Label0 and Label1 to be italic but Text 2 to not be italic?
I tried
Me.Text4 = Me.Label0.Caption.fontital ic & " " & Me.Text2 & " " & Me.Label1.Caption.fontital ic
But that doesn't work.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.Text4 = Me.Label0.Caption & " " & Me.Text2 & " " & Me.Label1.Caption
End Sub
But now I have one more question... What if I need Label0 and Label1 to be italic but Text 2 to not be italic?
I tried
Me.Text4 = Me.Label0.Caption.fontital
But that doesn't work.
<But now I have one more question.>
Remember, only one question per post...
;-)
You can create a new question for this new issue, as it is a bit tricky to accomplish...
JeffCoachman
Remember, only one question per post...
;-)
You can create a new question for this new issue, as it is a bit tricky to accomplish...
JeffCoachman
...if you still need the formatting, I think I may have something for you...
I'll wait to see if you post a new Q...
I'll wait to see if you post a new Q...
http://www.dbforums.com/microsoft-access/1213941-resizing-textbox-report.html
Personally, I have never found any real definitive solution to retrieving the width of a String in Twips dependant upon the font size and the Control it may reside in. But I have come up with something that is relatively close and may do the job.
It requires the use of a few Windows API functions, in particular the apiGetFocus function so as to acquire the Handle (hWnd) of the MS-Access Control which contains the text String, the GetWindowDC function so as to acquire the Device Context (DC) of the Control window, and finally the GetTextExtentPoint32 function so as to determine the length of the String located within the Control in Points.
All these API functions are put to work within another function I call GetStringWidthInTwips and delivers the Twip String Width which can be used to either make wider or narrower the Control which contains the String value.
To begin, Place the following code into a Database Code Module:
Code:
Open in new window
Notice that I've also tossed the function named GetStringHeightInTwips into the mix. Do with it as you will.Now...to use all this mess simple do this:
Code:
Open in new window
If someone has found a better way to do this then please....SHARE IT.
Hope this helps.