View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Transferring Captions/Text between UserForms

One way is to declare a public variable in a General module--outside any
procedu

Public MyVar as string

Then that variable will be able to be seen from any procedure.

=====
Alternatively, I could use a public variable in the userform1 module:

Option Explicit
Public myVar As String
Private Sub CommandButton1_Click()
UserForm2.Show
Me.TextBox1.Text = myVar
End Sub

Then I could address it this way:

Option Explicit
Private Sub optionbutton1_Click()
UserForm1.myVar = Me.OptionButton1.Caption
Unload Me
End Sub




IT_roofer wrote:

This might be hard to explain...

I have a useform with 24 buttons and 24 textboxes. Each button corresponds
to a textbox next to it. The idea is to click a button to open up another
userform with several optionbuttons, then click the optionbutton and have the
optionbutton caption be put into the textbox that corrisponds to the button
that was originally clicked. (hope that makes sense)

I have tried assigning a variable (as String) to pass between the userforms,
but the caption gets lost (comes back blank).

(on UserForm1)
Private Sub cmdbutton_Click()
Dim myVar as String
buttonbox.Text = myVar
UserForm2.Show
End Sub

(on UserForm2)
Private Sub optionbutton1_Click()
myVar = optionbutton1.Caption
Unload Me
End Sub


--

Dave Peterson