Maximum width of text within VBA textbox control

Maximum width of text within VBA textbox control

Anonymous
Not applicable
1,375 Views
7 Replies
Message 1 of 8

Maximum width of text within VBA textbox control

Anonymous
Not applicable
Does anyone have a method to find the maximum width of text within a VBA multiline text box? I'd like something to find the longest line of text of a note such as: 8" CONCRETE CAP SLAB REINFORCE W/ #5 @ 8" O.C. EA WAY ELEVATION TOP SLAB 108-0 The only property I can find is the .CurX Property. VB has the .Textwidth method, but it doesn't appear to exist in VBA. The reason is I'd like to size the textbox control to be fairly representative of the maximum length of the longest line within the textbox control.
0 Likes
1,376 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
You can use the X value of the BoundingBox property. -- ---- Ed ---- "Allen Johnson" wrote in message news:41b4897d$1_2@newsprd01... > Does anyone have a method to find the maximum width of text within a VBA > multiline text box? > I'd like something to find the longest line of text of a note such as: > > 8" CONCRETE CAP SLAB > REINFORCE W/ #5 @ 8" O.C. EA WAY > ELEVATION TOP SLAB 108-0 > > The only property I can find is the .CurX Property. > VB has the .Textwidth method, but it doesn't appear to exist in VBA. > > The reason is I'd like to size the textbox control to be fairly > representative of the maximum length of the longest line within the textbox > control. > >
0 Likes
Message 3 of 8

Anonymous
Not applicable
But I actually want to know how wide the text is in the textbox, not the drawing. "Ed Jobe" wrote in message news:41b48ab5$1_1@newsprd01... > You can use the X value of the BoundingBox property. >
0 Likes
Message 4 of 8

Anonymous
Not applicable
I see now. How about setting AutoSize to True? -- ---- Ed ---- "Allen Johnson" wrote in message news:41b48b4e$1_1@newsprd01... > But I actually want to know how wide the text is in the textbox, not the > drawing. > > "Ed Jobe" wrote in message > news:41b48ab5$1_1@newsprd01... > > You can use the X value of the BoundingBox property. > > > >
0 Likes
Message 5 of 8

Anonymous
Not applicable
Good idea! Thanks. With txtNotes .AutoSize = True .Text = TextString tbw = .Width .AutoSize = False .Width = 1.2 * tbw .Left = (Me.Width - .Width) / 2 .Height = 95 End With "Ed Jobe" wrote in message news:41b4921c_1@newsprd01... > I see now. How about setting AutoSize to True?
0 Likes
Message 6 of 8

Anonymous
Not applicable
You're welcome. Another FYI, might be to calulate it from the width of a char (in points), multiplied by the LEN of the widest string. Although I think you've got the easier way. -- ---- Ed ---- "Allen Johnson" wrote in message news:41b4956f$1_1@newsprd01... > Good idea! Thanks. > > With txtNotes > .AutoSize = True > .Text = TextString > tbw = .Width > .AutoSize = False > .Width = 1.2 * tbw > .Left = (Me.Width - .Width) / 2 > .Height = 95 > End With > > > "Ed Jobe" wrote in message > news:41b4921c_1@newsprd01... > > I see now. How about setting AutoSize to True? > >
0 Likes
Message 7 of 8

Anonymous
Not applicable
Don't forget to resize your form to fit your resized textbox. Sooner or later you will be resizing other items and then you may run into the frustrating problem of your newly calculated resized objects not always updating to the resized dimension.
0 Likes
Message 8 of 8

Anonymous
Not applicable
i'm looking for the same capability in MS Access VBA. is there a similar property in Access 2003? i can't seem to find AutoSize or a current corollary to AutoSize when in form view.

From VBA help: Can Grow and Can Shrink: This property affects the display of form sections and controls only when the form is printed or previewed, not when the form is displayed in Form view, Datasheet view, or Design view.
0 Likes