Hello,
I am using the code below to dynamicaly create labels in a form.
I have 2 issues:
Sizing of the form containing the labels:
I would like the height of the form to adjust with the number of labels. It seems that a height of 10 for a label is not the same height for a height of 10 for the form that contain the label.
Is there a way to force the same scale. (Blue bellow)
The .Font.Name (in red below) doesn't work although the lines above and after work perfectly.
I can write anything instead of "Courier new" it doesn't pop an error, nor does it change the font in the labels.
If I type msgbox .Font.Name after my line, it shows "Courier New" and my symbols are proportional which is not what I want.
Does any one have a idea?
Option Explicit
Private Sub UserForm_Activate()
Dim MyAmountTbl As Variant, NBCRecord As Variant, NBCRecordValue As Variant, MyDescTbl As Variant
Dim MyLabels() As Object
Dim MyLeft As Long, T As Long, LonguestStr As Long, MyWidth As Long, LabelCounter As Long, MyHeight As Long
MyLeft = 2: MyWidth = 300: MyHeight = 10
MyAmountTbl = Split(MyAmountTbl, ",")
MyDescTbl = Split(MyDescTbl, "|")
ReDim MyLabels(0 To UBound(MyAmountTbl))
With NBCMultipleBills 'Form
.Caption = "Detailed payement for: USD " & Format(NBCRecordValue(1, 6), "# ###.#0")
.Width = MyWidth + 14
.Height = 2 + ((UBound(MyAmountTbl) + 1) * MyHeight)
End With
LonguestStr = 0
For T = 0 To UBound(MyAmountTbl)
If Len(Format(MyAmountTbl(T), "# ###.#0")) > LonguestStr Then LonguestStr = Len(Format(MyAmountTbl(T), "# ###.#0"))
Next
For T = 0 To UBound(MyAmountTbl)
Set MyLabels(T) = NBCMultipleBills.Controls.Add("Forms.Label.1", "Test" & LabelCounter, True)
With MyLabels(T)
.Caption = WorksheetFunction.Rept(">", LonguestStr + 1 - Len(Format(MyAmountTbl(T), "# ###.#0")))
.Caption = .Caption & Trim(MyDescTbl(T))
.Width = MyWidth
.Font.Name = "Courier New"
.Font.Size = 8
.Left = MyLeft
.Height = MyHeight
.BackColor = VeryLightBlue
.Top = 2 + ((.Height + 3) * T)
End With
Next T
End Sub
I am using the code below to dynamicaly create labels in a form.
I have 2 issues:
Sizing of the form containing the labels:
I would like the height of the form to adjust with the number of labels. It seems that a height of 10 for a label is not the same height for a height of 10 for the form that contain the label.
Is there a way to force the same scale. (Blue bellow)
The .Font.Name (in red below) doesn't work although the lines above and after work perfectly.
I can write anything instead of "Courier new" it doesn't pop an error, nor does it change the font in the labels.
If I type msgbox .Font.Name after my line, it shows "Courier New" and my symbols are proportional which is not what I want.
Does any one have a idea?
Option Explicit
Private Sub UserForm_Activate()
Dim MyAmountTbl As Variant, NBCRecord As Variant, NBCRecordValue As Variant, MyDescTbl As Variant
Dim MyLabels() As Object
Dim MyLeft As Long, T As Long, LonguestStr As Long, MyWidth As Long, LabelCounter As Long, MyHeight As Long
MyLeft = 2: MyWidth = 300: MyHeight = 10
MyAmountTbl = Split(MyAmountTbl, ",")
MyDescTbl = Split(MyDescTbl, "|")
ReDim MyLabels(0 To UBound(MyAmountTbl))
With NBCMultipleBills 'Form
.Caption = "Detailed payement for: USD " & Format(NBCRecordValue(1, 6), "# ###.#0")
.Width = MyWidth + 14
.Height = 2 + ((UBound(MyAmountTbl) + 1) * MyHeight)
End With
LonguestStr = 0
For T = 0 To UBound(MyAmountTbl)
If Len(Format(MyAmountTbl(T), "# ###.#0")) > LonguestStr Then LonguestStr = Len(Format(MyAmountTbl(T), "# ###.#0"))
Next
For T = 0 To UBound(MyAmountTbl)
Set MyLabels(T) = NBCMultipleBills.Controls.Add("Forms.Label.1", "Test" & LabelCounter, True)
With MyLabels(T)
.Caption = WorksheetFunction.Rept(">", LonguestStr + 1 - Len(Format(MyAmountTbl(T), "# ###.#0")))
.Caption = .Caption & Trim(MyDescTbl(T))
.Width = MyWidth
.Font.Name = "Courier New"
.Font.Size = 8
.Left = MyLeft
.Height = MyHeight
.BackColor = VeryLightBlue
.Top = 2 + ((.Height + 3) * T)
End With
Next T
End Sub