Results 1 to 5 of 5
  1. #1
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338

    text box to grow or shrink horizontally

    Hi
    In my report, i have a text box and label field next to it. I want the text box to grow or shrink horizontally with the text size and the label field to float back and forth with it.

    Thank you






  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    There is no property for 'grow horizontally'. VBA code might be able to manage this but wouldn't be easy.
    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
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    June7

    I was able to find vba code online to grow or shrink horizontally. The code is below. Can you help me with making label field float back and forth?

    Module
    Option Compare Database
    Option Explicit
    ' Type Declaration for the GetTextExtentPoint32 function.
    Private Type POINTAPI
    X As Long
    Y As Long
    End Type

    ' The API function to retreive the width and Height of
    ' a String (in Points).
    Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias _
    "GetTextExtentPoint32A" (ByVal hdc As Long, _
    ByVal lpsz As String, ByVal cbString As Long, _
    lpSize As POINTAPI) As Long

    ' The API function used to acguire the Device Context
    ' (DC) of a Window (or Control).
    Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long

    ' The API function used to acquire the Handle (hWnd)
    ' of a MS-Access Control. MS-Access Controls don't
    ' have a Handle because they are drawn to screen as
    ' when required. Once it's drawn, we can then get a
    ' Handle.
    Private Declare Function apiGetFocus Lib "user32" _
    Alias "GetFocus" () As Long


    Public Function GetStringWidthInTwips(Ctrl As Control) As Long
    Dim TextSize As POINTAPI
    Dim nDC As Long
    Dim mWnd As Long
    Dim Strg As String

    ' Fill the Value of the Control into the Strg String variable.
    Strg = CStr(Ctrl.Text)
    'Get the Handle (hWnd) of the Control
    mWnd = GethWnd(Ctrl)
    'Get the Control's device context
    nDC = GetWindowDC(mWnd)
    'Get the width of our Text String
    GetTextExtentPoint32 nDC, Strg, Len(Strg), TextSize
    ' Convert the the determined text length (in points) to Twips.
    ' You may need to play with the value of 1.358 to suit your
    ' needs.
    GetStringWidthInTwips = (TextSize.X * (Ctrl.FontSize * 1.45))
    End Function

    Public Function GetStringHeightInTwips(Ctrl As Control) As Long
    Dim TextSize As POINTAPI
    Dim nDC As Long
    Dim mWnd As Long
    Dim Strg As String
    ' Fill the Value of the Control into the Strg String variable.
    Strg = CStr(Ctrl.Text)
    'Get the Handle (hWnd) of the Control
    mWnd = GethWnd(Ctrl)
    'Get the Control's Device Context
    nDC = GetWindowDC(mWnd)
    'Get the Height of our Text String
    GetTextExtentPoint32 nDC, Strg, Len(Strg), TextSize
    ' Convert the the determined text Height (in points) to Twips.
    ' You may need to play with the value of 1.3 to suit your
    ' needs.
    GetStringHeightInTwips = (TextSize.Y * (Ctrl.FontSize * 1.3))
    End Function

    Private Function GethWnd(ctl As Control) As Long
    ' Acquire the Handle (hWnd) of the passed
    ' MS -Access Control.
    On Error Resume Next
    ' Make sure the passed Control has Focus.
    ctl.SetFocus
    If Err Then ' if focus can not be achieved then return 0
    GethWnd = 0
    Else ' otherwise, get the Handle
    GethWnd = apiGetFocus
    End If
    On Error GoTo 0
    End Function

    Report Detail
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Me.REASON.Width = GetStringWidthInTwips(Me.REASON)
    Me.Label32.Left = TextWidth(varLeftCol) + 5250
    End Sub



  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    'Floating' label I guess could involve setting Left property or maybe the Width of the label. Might have to disassociate label from control. Never tried anything like this.

    Are you using proportional font? Does this function work adequately with that?
    Last edited by June7; 01-29-2013 at 08:06 PM.
    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
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    yes it works great.

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

Similar Threads

  1. Replies: 1
    Last Post: 10-10-2012, 12:25 PM
  2. Force Can Shrink
    By RMI in forum Reports
    Replies: 2
    Last Post: 11-12-2011, 10:56 AM
  3. Grow text box on form with focus
    By Karen H in forum Forms
    Replies: 5
    Last Post: 02-25-2011, 12:03 PM
  4. Text box resize horizontally
    By cowboy in forum Reports
    Replies: 1
    Last Post: 06-09-2010, 09:30 PM
  5. Can Shrink control
    By fojcenter in forum Forms
    Replies: 1
    Last Post: 02-25-2010, 03:49 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