B
Bill Cunningham
Hello,
I'm trying to get a macro to check the values of a set of
textboxes in a vba userform, and create a single string of
their contents.
Any one or more of the textboxes might have text in them,
and the set of textboxes may be filled in multiple times
(basically, there are 5 available boxes for data. When the
user has filled them all in they have the choice of ending
there or using more boxes. If the click "More", the macro
will create a string of all the current values, then clear
them and allow the user to enter 5 more. This may continue
indefinately.)
In order for this to work, though, I need to put the vba
code representing the name of the userform textboxes into
a variable. The textboxes are named:
txtListItem1, txtListItem2, ... etc.
Here is the code I'm trying to make work:
----------------------------------------
Sub WriteList()
Dim ItemName as String, ItemNo As Integer
For ItemNo = 1 To 5
ItemName = "txtListItem" & ItemNo
If Len(Trim(ListString)) = 0 Then
If Len(Trim(ItemName)) <> 0 Then
ListString = ItemName
End If
Else
If Len(Trim(ItemName)) <> 0 Then
ListString = ListString & vbCr & ItemName
End If
End If
Next
End Sub
-------------------------------------
Of course, what is happening is the varible "ItemName" is
just being filled with the actual name of the textbox, not
the value of the textbox.
How can I get the ItemName variable to take on the value
of the textbox I'm naming?
Thanks!
I'm trying to get a macro to check the values of a set of
textboxes in a vba userform, and create a single string of
their contents.
Any one or more of the textboxes might have text in them,
and the set of textboxes may be filled in multiple times
(basically, there are 5 available boxes for data. When the
user has filled them all in they have the choice of ending
there or using more boxes. If the click "More", the macro
will create a string of all the current values, then clear
them and allow the user to enter 5 more. This may continue
indefinately.)
In order for this to work, though, I need to put the vba
code representing the name of the userform textboxes into
a variable. The textboxes are named:
txtListItem1, txtListItem2, ... etc.
Here is the code I'm trying to make work:
----------------------------------------
Sub WriteList()
Dim ItemName as String, ItemNo As Integer
For ItemNo = 1 To 5
ItemName = "txtListItem" & ItemNo
If Len(Trim(ListString)) = 0 Then
If Len(Trim(ItemName)) <> 0 Then
ListString = ItemName
End If
Else
If Len(Trim(ItemName)) <> 0 Then
ListString = ListString & vbCr & ItemName
End If
End If
Next
End Sub
-------------------------------------
Of course, what is happening is the varible "ItemName" is
just being filled with the actual name of the textbox, not
the value of the textbox.
How can I get the ItemName variable to take on the value
of the textbox I'm naming?
Thanks!