Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

trying to word wrap text in a field on a subform

trying to word wrap text a field in a subform
access 365

I'm trying to word wrap a field on a subform
using the code below.
I have tried the before_update  and  form_current

Private Sub Form_Current()
' MAX AMOUNT OF CHARACTERS UNTIL THE TEXTBOX WILL WORD WRAP
Const INCREASE_LINE_HEIGHT = 50
' ORIGINAL HEIGHT OF THE TEXTBOX
Const ORIGINAL_HEIGHT = 0.2035
' USED TO CONVER INCHES TO TWIPS
Const TWIPS = 1440
' USED TO DETERMINE THE SIZE OF THE TEXT BOX HEIGHT
Dim line_count As Integer
' holds text box text
Dim txtData As String
' holds textbox character length
Dim txtLength As String
' holds the number of times the text size should increase
Dim boxlines As Integer
' assign text box text
txtData = Nz(Me.WWG_Additional_Description, "")
' assign textbox length
txtLength = Len(txtData)

' if the amount of characters is created than increase the line height, then the text box size needs to be increased
' else the textbox goes back to its original state
If txtLength > INCREASE_LINE_HEIGHT Then
' get the amount of new lines required rounded up by 1
   boxlines = Int(txtLength / INCREASE_LINE_HEIGHT) + 1
' resized the textbox by the multiplying  the original height * the number of new lines * twips
   Me.WWG_Additional_Description.Height = ORIGINAL_HEIGHT * boxlines * TWIPS
Else
' default to original state
   boxlines = 1
   Me.WWG_Additional_Description.Height = ORIGINAL_HEIGHT * TWIPS
End If
End Sub

Open in new window


Is it even possible ?

Thanks
fordraiders
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Because some wrong assumptions may arise can you give a screenshot of what you are after?
Giving us code that may or may not work doesn't really help.  What EXACTLY are you trying to do?  Are you trying to replicate Word's ability to adjust text to fit in a certain space and make it look "pretty"?  Why not export your report to work and let Word solve your problem for you?  You can make a word template with bookmarks and place the text in the bookmarks.

Uploading your database so we can see the code in action would also help.  But please tell us what is wrong with what your current results are.
ASKER CERTIFIED SOLUTION
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fordraiders

ASKER

THANKS ALL.