H
Hank Youngerman
In a VBA program I load a userform with buttons and combo boxes,
populate the combo boxes, and then show the form.
The main subroutine seems to pause execution while the userform is
visible, then resumes when the form is hidden. That seems a little
weird to me. I mean, what if I wanted the program to continue? What
if I wanted it to be reading a whole bunch of data or doing
calculations while the user thought about his choices? Is there a way
to force it to continue? But that's not the main question.
On the userform I have buttons for continue and exit. Continue simply
hides the userform. (I can't unload it or else I lose the values
chosen in the combo boxes.) I have to have exit do something else.
Right now, what I do is have the exit command button set one of the
combo box values to an impossible value. Then when control goes back
to the main subroutine, if the value is that, I unload the userform and
exit sub.
Two questions on this:
1) Is there a way to pass a variable without it being a value on the
userform? Obviously, I could create a text box on the form, make it
invisible, and use that, but it's the same effect. There is probably
some way to make a variable "global" or "public" but how do I do that?
2) Is there a way to do this without passing variables. Can I have the
Exit button just terminate the main subroutine?
The outline of the code appears below. Thanks.
____________________________________
Code behind Sheet1:
Private sub mainsub_click()
load userform1
userform1.combobox1.additem 1
userform1.combobox1.additem 2
userform1.show
if userform1.combox1.value = -1 then exit sub
msgbox "The value of userform1 combo box is" &
userform1.combobox1.value
end sub
Code behind userform1:
Private sub continue_click()
userform1.hide
end sub
Private sub exit_click()
userform1.combobox1.value = -1
userform1.hide
end sub
populate the combo boxes, and then show the form.
The main subroutine seems to pause execution while the userform is
visible, then resumes when the form is hidden. That seems a little
weird to me. I mean, what if I wanted the program to continue? What
if I wanted it to be reading a whole bunch of data or doing
calculations while the user thought about his choices? Is there a way
to force it to continue? But that's not the main question.
On the userform I have buttons for continue and exit. Continue simply
hides the userform. (I can't unload it or else I lose the values
chosen in the combo boxes.) I have to have exit do something else.
Right now, what I do is have the exit command button set one of the
combo box values to an impossible value. Then when control goes back
to the main subroutine, if the value is that, I unload the userform and
exit sub.
Two questions on this:
1) Is there a way to pass a variable without it being a value on the
userform? Obviously, I could create a text box on the form, make it
invisible, and use that, but it's the same effect. There is probably
some way to make a variable "global" or "public" but how do I do that?
2) Is there a way to do this without passing variables. Can I have the
Exit button just terminate the main subroutine?
The outline of the code appears below. Thanks.
____________________________________
Code behind Sheet1:
Private sub mainsub_click()
load userform1
userform1.combobox1.additem 1
userform1.combobox1.additem 2
userform1.show
if userform1.combox1.value = -1 then exit sub
msgbox "The value of userform1 combo box is" &
userform1.combobox1.value
end sub
Code behind userform1:
Private sub continue_click()
userform1.hide
end sub
Private sub exit_click()
userform1.combobox1.value = -1
userform1.hide
end sub