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
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
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.
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
'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.
yes it works great.