View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
James Neumann[_2_] James Neumann[_2_] is offline
external usenet poster
 
Posts: 4
Default Using a string to point to a form object?

Try the following, which should give you some ideas...

Create a form with three text boxes, and one command button:

txt_1
txt_2
txt_3

CommandButton1

Copy the code below behind the command button:

Private Sub CommandButton1_Click()

Dim i As Integer
Dim txtSource As MSForms.TextBox
Dim strTest As String

For i = 1 To 3
Set txtSource = Me.Controls("txt_" & i)
strTest = txtSource.Text
Next i

Set txtSource = Nothing

End Sub

Not very elegant, but it will give you the values in teh text boxes.
All you need to do is refer to the controls collection with the correct
name - this type of reference will also work with dynamically created
controls.

HTH

Please remove NOSPAM to email, and please post any replies directly to
group.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!