Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Transferring Captions/Text between UserForms

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Transferring Captions/Text between UserForms

That did the trick. Thanks for the help.

I do have a question about using myVar in a Public statement... I have 23
other buttons and text boxes that will need to perform this same function.
Can I use that same myVar variable to transfer captions back and forth?

"Dave Peterson" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Transferring Captions/Text between UserForms

I imagine you could, but I don't think I would.

I think I'd add a button to the second workbook that accumulated the captions to
pass back and send them back as an array.

Inside the General module:

Option Explicit
'as many textboxes and optionbuttons you have
Public myVars(1 To 23) As String


Behind Userform1:

Option Explicit
Private Sub CommandButton1_Click()
Dim iCtr As Long
UserForm2.Show
For iCtr = LBound(myVars) To UBound(myVars)
Me.Controls("textbox" & iCtr).Value = myVars(iCtr)
Next iCtr
End Sub

Behind userform2:

Option Explicit
Private Sub CommandButton1_Click()
Dim iCtr As Long
'you know how many optionbuttons you have
'and you named them nicely
'OptionButton1, OptionButton2, ...OptionButton23
For iCtr = LBound(myVars) To UBound(myVars) 'I only had 2!
With Me.Controls("OptionButton" & iCtr)
If .Value = True Then
myVars(iCtr) = .Caption
Else
myVars(iCtr) = "" 'empty string?
End If
End With
Next iCtr
Unload Me
End Sub

==========
And I'm assuming that the optionbuttons are grouped nicely--without being
grouped, you'll only be able to select a single optionbutton.

And notice that my OptionButtons and Textboxes are named nicely--so
Optionbutton17 and textbox17 will be "associated" with each other.



IT_roofer wrote:

That did the trick. Thanks for the help.

I do have a question about using myVar in a Public statement... I have 23
other buttons and text boxes that will need to perform this same function.
Can I use that same myVar variable to transfer captions back and forth?

"Dave Peterson" wrote:

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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transferring text from one worksheet to another txmusic Excel Discussion (Misc queries) 1 March 18th 10 02:18 AM
Formatting Text Boxes & Label Captions in MultiPages Drummer361 Excel Programming 0 August 16th 06 01:09 AM
transferring from excel to text lbierer New Users to Excel 1 December 1st 05 09:06 PM
Sending/Transferring Text? Clint Keller Excel Programming 1 May 19th 04 11:09 PM
Transferring data entered into a Text box to another Cell/Sheet? Alan T[_2_] Excel Programming 1 October 29th 03 12:54 AM


All times are GMT +1. The time now is 09:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"