Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Transferring text from one worksheet to another | Excel Discussion (Misc queries) | |||
Formatting Text Boxes & Label Captions in MultiPages | Excel Programming | |||
transferring from excel to text | New Users to Excel | |||
Sending/Transferring Text? | Excel Programming | |||
Transferring data entered into a Text box to another Cell/Sheet? | Excel Programming |