Hello Folks,
I was able to find the below code to align text vertically in Labels and TextBoxes. However; I haven't been able to figure out where do I place this code and how do I use it? Do I have to make any changes to this code?
Please help!
'Sets the vertical alignment of a label or textbox to "Center"
'NOTE:
'MinimumMargin: the value of the smallest margin Access allows in twips. If you set the .TopMargin
'to "0", Access will actually place a gap equal to 1 point (or 20 twips) rather than actually
'placing the text at the very top border of the control. FURTHER NOTE: Access sucks.
'BorderWidth: half the value of .BorderWidth in twips. As you increase the border (Hairline, 1pt, 2pt, etc..)
'Access expands the border equally from the center. We're only concerned with the "inner" section of the border.
'TwipsPerPoint: global constant set to 20
Public Sub VerticalAlignCenter(ByRef ctl As Control)
On Error GoTo ErrorCode
Dim MinimumMargin As Integer
Dim BorderWidth As Integer
If Not ((TypeOf ctl Is TextBox) Or (TypeOf ctl Is Label)) Then Exit Sub
MinimumMargin = 1 * TwipsPerPoint
BorderWidth = (ctl.BorderWidth * TwipsPerPoint) / 2
ctl.TopMargin = ((ctl.Height - (ctl.FontSize * TwipsPerPoint)) / 2) - MinimumMargin - BorderWidth
ErrorCode:
Exit Sub
End Sub
I was able to find the below code to align text vertically in Labels and TextBoxes. However; I haven't been able to figure out where do I place this code and how do I use it? Do I have to make any changes to this code?
Please help!
'Sets the vertical alignment of a label or textbox to "Center"
'NOTE:
'MinimumMargin: the value of the smallest margin Access allows in twips. If you set the .TopMargin
'to "0", Access will actually place a gap equal to 1 point (or 20 twips) rather than actually
'placing the text at the very top border of the control. FURTHER NOTE: Access sucks.
'BorderWidth: half the value of .BorderWidth in twips. As you increase the border (Hairline, 1pt, 2pt, etc..)
'Access expands the border equally from the center. We're only concerned with the "inner" section of the border.
'TwipsPerPoint: global constant set to 20
Public Sub VerticalAlignCenter(ByRef ctl As Control)
On Error GoTo ErrorCode
Dim MinimumMargin As Integer
Dim BorderWidth As Integer
If Not ((TypeOf ctl Is TextBox) Or (TypeOf ctl Is Label)) Then Exit Sub
MinimumMargin = 1 * TwipsPerPoint
BorderWidth = (ctl.BorderWidth * TwipsPerPoint) / 2
ctl.TopMargin = ((ctl.Height - (ctl.FontSize * TwipsPerPoint)) / 2) - MinimumMargin - BorderWidth
ErrorCode:
Exit Sub
End Sub