Pressing a CommandButton on a Userform via Code

C

Corey

I want to have a user click a Commandbutton on Userform5 that will Show
Userform8.
This is OK,
Userform8 has a CommandButton1 to View a Sheet in PrintPreview.
How can i get the Userform8 CommandButton to to Coded to Run to the Preview
with out having to press it ?


I tried:
Call Userform8.Commandbutton1 but get an error
also tried:

Call CommandButton1 but still get an error.

How can this be done?
Corey....
 
C

Corey

Hmm.
Still a bit puzzled.

So how would I :
Using Commandbutton3 on Userform5 i copied the code that i normally use to
unload the uersorm data into a sheet.
i want to add at the end of this code the following:
Userform4.Show & use the value that was in Userform5.Textbox195 as the
selected value in Userform4.Combobox1.value,
then Press the CommandButton1 of Userform4(CommandButton1.Value = True),
then
this Button inputs data from the sheet that Userform5 also add data to,
thendisplays a 1 page sheet with the data placed in the relative cells in
Print Preview mode.

I am having trouble carrying the value from Userform5 through to Userform4,
and getting each of the Userforms no longer require to Close off correctly.

Any idea's of the most efective way to do this?

I tried copying ALL code into the CommandButton3 code on Userform5 but it
took forever and stalled at stages with errors.

Corey....
 
N

NickHK

Corey,
Not sure about everything you're after, but....

with Userform4
.load 'but not show yet
.Combobox1.value=userform5.textbox195.text
userform5.hide
'or
unload userform5
.show 'vbmodal or vbmodeless
end with

NickHK
 
C

Corey

What does this do:
'vbmodal or vbmodeless

??
NickHK said:
Corey,
Not sure about everything you're after, but....

with Userform4
.load 'but not show yet
.Combobox1.value=userform5.textbox195.text
userform5.hide
'or
unload userform5
.show 'vbmodal or vbmodeless
end with

NickHK
 
C

Chip Pearson

What does this do:
'vbmodal or vbmodeless

It indicates that either the vbModal or the vbModeless constant value should
be provided to the Show command. With vbModal, you can interact only with
the form until the form is hidden or unloaded. You can't access anything
outside the form, and code execution pauses on the Show statement until the
form is dismissed. With vbModeless, the form is shown and execution proceeds
past the Show statement. With a modeless form, you can interact with the
Excel environment while the form is still visible. If neither vbModal or
vbModeless parameter is omitted the form is show modal unless the ShowModal
property is set to False.



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
Joined
Jan 19, 2007
Messages
3
Reaction score
0
Any reason you're not calling the function directly?

If the button is coded to call a function, why not just skip the button press and call the function directly?

It would probably involve refactoring the code so that it doesn't live directly on the userform, but it sounds like this would be the "correct" way to do what you'd like. Maybe a new module or class that handles these types of global calls?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top