Results 1 to 9 of 9
  1. #1
    JonMulder is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    24

    Find Maximum TextHeight of Textboxes in Report's Detail Section

    Greetings,



    I've been wracking my brains out on this and finally decided to post. It looks like I can use a control's textheight property to determine the textbox that has the largest height in my detail section. Then I can adjust all of the control heights to that same number. I'm using the following code:

    Code:
    Dim intMaxHeight As Integer
    Dim ctl As Control
    For Each ctl In Me.Section(0).Controls
    If ctl.ControlType = acTextBox Then
       If Me.TextHeight(ctl.Value) > intMaxHeight Then
          intMaxHeight = Me.TextHeight(ctl.Value)
       End If
       MsgBox (vbNewLine & ctl.Value & vbNewLine & Me.TextHeight(ctl.Value))
    End If
    Next
    I have stepped through the code and my control's textheight value always remains 269. I have checked the control's textwidth, and that changes as it should. Any ideas why my textheight doesn't return the proper value. I've tried with the textbox's "Can Grow" property to both True and False. Below is some of the debugging I stepped through. As you can see, the textwidth changes, but the text height does not change.

    ?ctl
    CARPINTERIA hjuhj oiopi[piop oi[po[po[po[p [po][o]op][ iuiyuyuf opi[pp[o[po[p tt76t78 8y7896896 oioi
    Carpinteria Valley Water District
    CARPINTERIA hjuhj oiopi[piop oi[po[po[po[p [po][o]op][ iuiyuyuf opi[pp[o[po[p tt76t78 8y7896896 oioi
    Carpinteria Valley Water District
    CARPINTERIA
    Carpinteria Valley Water District
    ?ctl.Name
    TextBoxMEName
    ?ctl.width
    2100
    2880
    2880
    ?ctl.height
    1860
    1860
    1860
    ?textheight(ctl)
    269
    269
    269
    269
    ?textwidth(ctl)
    9216
    9216
    2863
    1195
    2863


    Thanks for any help you can provide!

    Jonathan Mulder
    Last edited by June7; 01-08-2015 at 11:48 AM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why do you need to programmatically set textbox height and width?

    CanGrow/CanShrink just works for reports. Don't know why they even show up on form properties.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    JonMulder is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    24
    Thanks for the response, June7, and Happy New Year!.

    Let me elaborate. I have about 15 textboxes with visible borders in the detail section of a report. Most of them have just a few characters of text and need only one line to show the text. Sometimes, the CompanyName textbox can contain a large amount of text (say 100 characters) and it need to "word-wrap" so that the text is three lines long. Ideally, I'd like to check for the textbox that has the greatest height. In searching the forums, it looks like I should loop through the textbox controls and get the textbox height that is the greatest. Then I should assign that height to all of the other textboxes. Also, it would be really nice, if I could center the one-line textbox text in the textbox. In other words, if CompanyName is three lines long, the one-line textboxes should start at line 2 thereabout. It seemed the textheight(ctl) was the way to go but I may be mistaken.

    I've rummaged through the web but can't find an explicit solution. I've looked at Leban's website and he had something to center text, but now I can't find it. I'm thinking this is a common process to do. After all, in Excel, one can format text in a cell to be vertically centered.

    Jonathan Mulder
    Engineering Geologist
    California Department of Water Resources
    Red Bluff, CA

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The thread title indicates this is for a form, not report.

    Not something I would do. I basically never set borders as visible if text is going to be variable length. I might use a line control to define record separation. I have also used code to draw vertical lines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    JonMulder is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    24
    Ooops! My mistake! I meant REPORT, not Forms. I've seen some comments about using line objects instead of visible textbox borders. Nonetheless, I still have to get the maximum textbox height to pass to the vertical line objects, correct?

  6. #6
    Missinglinq's Avatar
    Missinglinq is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by June7 View Post

    CanGrow/CanShrink just works for reports. Don't know why they even show up on form properties.
    Works on Forms if they're being printed, which they shouldn't be, of course!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    JonMulder is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    24
    Yes, I meant reports, not forms. I can't find a way to change the Subject Line of the original posting from "Forms" to "Reports". None the less, as I stepped through it in the OnPrint procedure, it still gives me 269 twips (i.e., one line) when I can clearly see that the text will slop over into several lines.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Ah, thanks, Linq. That explains why those properties never seemed to work on form. I will correct the title.

    Sorry, no answer for you. As stated, not something I would do.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    After some tweaking, following code worked. Set the Can Grow property of textbox to YES. Further, have a look at the Textbox.LeftMargin property for aligning text within the text box.
    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim intMaxHeight As Integer
    Dim ctl As Control
    For Each ctl In Me.Section(0).Controls
    If ctl.ControlType = acTextBox Then
       If ctl.height > intMaxHeight Then
          intMaxHeight = ctl.height
       End If
    End If
    Next 
    For Each ctl In Me.Section(0).Controls
    If ctl.ControlType = acTextBox Then
    ctl.height = intMaxHeight
    End If
    Next 
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-13-2014, 12:26 PM
  2. Replies: 2
    Last Post: 01-09-2014, 07:24 PM
  3. Replies: 6
    Last Post: 03-26-2013, 12:17 PM
  4. Replies: 3
    Last Post: 01-19-2013, 01:37 PM
  5. Replies: 4
    Last Post: 07-10-2012, 01:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums