Results 1 to 3 of 3
  1. #1
    alexcalgary is offline Novice
    Windows XP Access 2003
    Join Date
    May 2009
    Posts
    3

    How to vertically align text inside a text box ?

    Hallo
    I have a large text box that prominently displays the contact name for the current record. But, I cannot find a way to vertically align the text inside this text box. I am aware of the format buttons on the Tool bar. They seem to do the same as the Text Align property on the property sheet; i.e. set the horizontal alignment in different ways.

    Further down on the property sheet are more options such as left margin, right margin, top margin, etc. I tried a few values in there but I am only making things worse.



    The text box is too big to ignore the poor vertical alignment of the text inside of it. What can I do ?

  2. #2
    hafaba is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    5

    Use Module to set the properties

    This is not as simple as setting vertical align in Excel cells. You need to create a function using modules

    1. Determine the high of the text box
    2. Determine the length of the textbox
    3. Determine the length of the string
    4. Set horizontal centre to the textbox

    Call the function from the textbox

    The function should be able to determine the top margin of the textbox based on the first three parameters mentioned above

    Hope this will give you / others ideas to solve this problem

  3. #3
    hafaba is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    5

    This is a simple Code

    Create a Form in Design View
    Create a Textbox to input the string and name it MyText
    Create a Large Textbox to display text with vertically align capability and name it as vText
    Create a commandbutton and name it as cmdVerticalAlign

    cmdVerticalAlign - Event OnClick, copy and paste the code below

    '==============================
    ' copy and paste this code
    ' created by hafaba in accessforums.net
    ' Permission given to use and to change this code
    ' provided my name remain unchanged
    '==============================
    Dim NumberofLine As Integer
    Dim TextboxWidth As Single
    Dim TextboxHeight As Single
    Dim LengthOfText As Integer

    Const FONTSIZEPERPIXEL = 100

    'MsgBox Me.vText.Width
    'MsgBox Me.vText.Height
    'MsgBox Len(Me.myText)

    LengthOfText = Len(Me.myText)
    TextboxWidth = Me.vText.Width
    TextboxHeight = Me.vText.Height


    NumberofLine = Int(LengthOfText * FONTSIZEPERPIXEL / TextboxWidth)
    Me.vText.TopMargin = (Me.vText.Height - (FONTSIZEPERPIXEL * NumberofLine)) / 2

    MsgBox NumberofLine

    Me.vText = Me.myText

    I am using the default Font for the textbox - Size 8 Tahoma. I haven't calculate the number of pixel for different size of Font. You have to do it manually by changing the CONST if you dont know how to determine the number of pixel for the font of your textbox! (sorry!)

    Forgive me for my bad english - Hope this will help you - bye

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

Similar Threads

  1. Write text to text box on a form
    By DKY in forum Programming
    Replies: 0
    Last Post: 10-08-2008, 11:34 AM
  2. joining text in text boxes
    By jjwilliams73 in forum Forms
    Replies: 1
    Last Post: 08-26-2008, 02:30 PM
  3. text box in table
    By texasguy4 in forum Access
    Replies: 0
    Last Post: 08-15-2008, 10:48 AM
  4. Split text field into two text fields
    By Grant in forum Access
    Replies: 6
    Last Post: 01-31-2008, 05:52 AM
  5. Unbound text box truncating text
    By gddrew in forum Forms
    Replies: 0
    Last Post: 03-02-2006, 11:26 AM

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