D
drako
Hi,
I'm attempting to create some dynamic controls within a Word VBA
userform.
What I am doing is reading in filenames from a directory, parsing the
filename, then creating a list of labels and textboxes based upon the
directory contents.
However, a strange problem I am having is that the LAST textbox to be
created always displays at the top left hand corner of the userform
(and does not display the text content either).
I really can't figure out what is wrong here.
Any suggestions ?
Code Extract below:
////////////////////////////////////
Private Sub UserForm_Initialize()
Dim t As Integer
t = 40
Dim counter As Integer
counter = 0
Dim tempString As String
Dim FName As String
FName = Dir(assetpath & "*.doc")
While FName <> ""
tempString = left(FName, Len(FName) - 4)
tempString = Replace(tempString, "_", " ")
FName = Dir
Dim mylabel As Label
Dim mylabel2 As Label
Dim myTextBox As TextBox
Set mylabel = asset_allocation_current.Controls.Add _
("Forms.Label.1", "asset_allocation_label_" & counter)
With mylabel
.left = 45
.Height = 16
.Top = t + (25 * counter)
.Width = 240
.Caption = tempString
End With
Set myTextBox = asset_allocation_current.Controls.Add _
("Forms.TextBox.1", "asset_allocation_boxes_" & counter)
With myTextBox
.left = 288
.Height = 16
.Top = (t + (25 * counter))
.Width = 60
.Text = counter
End With
Set mylabel2 = asset_allocation_current.Controls.Add _
("Forms.Label.1", "asset_allocation_label2_" & counter)
With mylabel2
.left = 350
.Height = 16
.Top = t + (25 * (counter))
.Width = 10
.Caption = "%"
End With
counter = counter + 1
Wend
End Sub
I'm attempting to create some dynamic controls within a Word VBA
userform.
What I am doing is reading in filenames from a directory, parsing the
filename, then creating a list of labels and textboxes based upon the
directory contents.
However, a strange problem I am having is that the LAST textbox to be
created always displays at the top left hand corner of the userform
(and does not display the text content either).
I really can't figure out what is wrong here.
Any suggestions ?
Code Extract below:
////////////////////////////////////
Private Sub UserForm_Initialize()
Dim t As Integer
t = 40
Dim counter As Integer
counter = 0
Dim tempString As String
Dim FName As String
FName = Dir(assetpath & "*.doc")
While FName <> ""
tempString = left(FName, Len(FName) - 4)
tempString = Replace(tempString, "_", " ")
FName = Dir
Dim mylabel As Label
Dim mylabel2 As Label
Dim myTextBox As TextBox
Set mylabel = asset_allocation_current.Controls.Add _
("Forms.Label.1", "asset_allocation_label_" & counter)
With mylabel
.left = 45
.Height = 16
.Top = t + (25 * counter)
.Width = 240
.Caption = tempString
End With
Set myTextBox = asset_allocation_current.Controls.Add _
("Forms.TextBox.1", "asset_allocation_boxes_" & counter)
With myTextBox
.left = 288
.Height = 16
.Top = (t + (25 * counter))
.Width = 60
.Text = counter
End With
Set mylabel2 = asset_allocation_current.Controls.Add _
("Forms.Label.1", "asset_allocation_label2_" & counter)
With mylabel2
.left = 350
.Height = 16
.Top = t + (25 * (counter))
.Width = 10
.Caption = "%"
End With
counter = counter + 1
Wend
End Sub