Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Which button was pressed?

I have a custom dialogue that I need to use in two very
different macros. Hence my OKButton_Click routine is empty
except for Unload UserForm, so that the calling macros can
each do their own thing.

But how can the calling macros tell if it was the OKbutton
or the Cancelbutton that was pressed?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Which button was pressed?



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adrian" wrote in message
...
I have a custom dialogue that I need to use in two very
different macros. Hence my OKButton_Click routine is empty
except for Unload UserForm, so that the calling macros can
each do their own thing.

But how can the calling macros tell if it was the OKbutton
or the Cancelbutton that was pressed?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Which button was pressed?

Adrian,

They would have separate click even ts so you can tell that way.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adrian" wrote in message
...
I have a custom dialogue that I need to use in two very
different macros. Hence my OKButton_Click routine is empty
except for Unload UserForm, so that the calling macros can
each do their own thing.

But how can the calling macros tell if it was the OKbutton
or the Cancelbutton that was pressed?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Which button was pressed?

Sorry Bob, I don't understand.

I have written Private subs that make my userform (named
ChooseCohort) work as required.
I've summoned the dialog from a Module (see below) but
after closing the dialog nothing happens (i.e. I can never
get the Msgbox to appear). That's one problem.
I'm calling the userform from a module (instead of putting
the code into the userform) so that I can use the form in
several different subs.

My other problem, and the one that I mentioned in my first
posting, is that I want it to do nothing if the Cancel
button was the way out of the userform.

Sub Test()
ChooseCohort.Show
If ChooseCohort.CheckBoxER1.Value = True Then MsgBox "ER1"
End Sub


-----Original Message-----
Adrian,

They would have separate click even ts so you can tell

that way.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adrian" wrote in message
...
I have a custom dialogue that I need to use in two very
different macros. Hence my OKButton_Click routine is

empty
except for Unload UserForm, so that the calling macros

can
each do their own thing.

But how can the calling macros tell if it was the

OKbutton
or the Cancelbutton that was pressed?



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Which button was pressed?

Adrian,

I see what you mean now.

If you Unload the form, the form is cleared from memory, so that when you do
the
If ChooseCohort.CheckBoxER1.Value = True Then MsgBox "ER1"
test it re-loads the form, but in it's initial state.

Instead of unloading the form, just hide it, it will saty in memory tehn.

Me.Hide

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adrian" wrote in message
...
Sorry Bob, I don't understand.

I have written Private subs that make my userform (named
ChooseCohort) work as required.
I've summoned the dialog from a Module (see below) but
after closing the dialog nothing happens (i.e. I can never
get the Msgbox to appear). That's one problem.
I'm calling the userform from a module (instead of putting
the code into the userform) so that I can use the form in
several different subs.

My other problem, and the one that I mentioned in my first
posting, is that I want it to do nothing if the Cancel
button was the way out of the userform.

Sub Test()
ChooseCohort.Show
If ChooseCohort.CheckBoxER1.Value = True Then MsgBox "ER1"
End Sub


-----Original Message-----
Adrian,

They would have separate click even ts so you can tell

that way.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adrian" wrote in message
...
I have a custom dialogue that I need to use in two very
different macros. Hence my OKButton_Click routine is

empty
except for Unload UserForm, so that the calling macros

can
each do their own thing.

But how can the calling macros tell if it was the

OKbutton
or the Cancelbutton that was pressed?



.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Which button was pressed?

Getting closer... thanks.
Two questions.

1. When (and how) do I unload the userform? Or do I leave
it and include some code to reset all the values before
the next .Show?

2. There is still the problem of distinguishing between
the OK and Cancel buttons. eg. the code below displays the
message whichever of those two I click.

Sub ChooseCohorts()
ChooseCohort.Show
If ChooseCohort.CheckBoxER1.Value = False Then MsgBox "Not
ER1"
End Sub

-----Original Message-----
Adrian,

I see what you mean now.

If you Unload the form, the form is cleared from memory,

so that when you do
the
If ChooseCohort.CheckBoxER1.Value = True Then MsgBox "ER1"
test it re-loads the form, but in it's initial state.

Instead of unloading the form, just hide it, it will saty

in memory tehn.

Me.Hide

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adrian" wrote in message
...
Sorry Bob, I don't understand.

I have written Private subs that make my userform (named
ChooseCohort) work as required.
I've summoned the dialog from a Module (see below) but
after closing the dialog nothing happens (i.e. I can

never
get the Msgbox to appear). That's one problem.
I'm calling the userform from a module (instead of

putting
the code into the userform) so that I can use the form

in
several different subs.

My other problem, and the one that I mentioned in my

first
posting, is that I want it to do nothing if the Cancel
button was the way out of the userform.

Sub Test()
ChooseCohort.Show
If ChooseCohort.CheckBoxER1.Value = True Then

MsgBox "ER1"
End Sub


-----Original Message-----
Adrian,

They would have separate click even ts so you can tell

that way.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the

Purbecks
(remove nothere from the email address if mailing

direct)

"Adrian" wrote in message
...
I have a custom dialogue that I need to use in two

very
different macros. Hence my OKButton_Click routine is

empty
except for Unload UserForm, so that the calling

macros
can
each do their own thing.

But how can the calling macros tell if it was the

OKbutton
or the Cancelbutton that was pressed?


.



.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Which button was pressed?

Adrian,

1. It depends, but the only 'true' answer is when you are absolutely done
with the form. Now it may be that there is no way to ascertain that, and
hence no way to identify where to unload it, but usually there is an
end-point somewhere. The main disadvantage is that memory is held by the
form until you unload it, but unless it is a big form with lots of code, or
there are many forms, this shouldn't be an issue.

2. I still do not understand this question. You talk of OK and Cancel
buttons, but the code refers to a Checkbox. If you want to know which button
was clicked, create a public variable, outside of procedure scope, and set
that in the button click events. Then test like so

If whichButton = "OK" then

where this assumes the variable is created in the standard module. If you
create it in the form module, you will need to qualify with the class

If ChooseCohort.whichButton = "OK" then

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adrian" wrote in message
...
Getting closer... thanks.
Two questions.

1. When (and how) do I unload the userform? Or do I leave
it and include some code to reset all the values before
the next .Show?

2. There is still the problem of distinguishing between
the OK and Cancel buttons. eg. the code below displays the
message whichever of those two I click.

Sub ChooseCohorts()
ChooseCohort.Show
If ChooseCohort.CheckBoxER1.Value = False Then MsgBox "Not
ER1"
End Sub

-----Original Message-----
Adrian,

I see what you mean now.

If you Unload the form, the form is cleared from memory,

so that when you do
the
If ChooseCohort.CheckBoxER1.Value = True Then MsgBox "ER1"
test it re-loads the form, but in it's initial state.

Instead of unloading the form, just hide it, it will saty

in memory tehn.

Me.Hide

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adrian" wrote in message
...
Sorry Bob, I don't understand.

I have written Private subs that make my userform (named
ChooseCohort) work as required.
I've summoned the dialog from a Module (see below) but
after closing the dialog nothing happens (i.e. I can

never
get the Msgbox to appear). That's one problem.
I'm calling the userform from a module (instead of

putting
the code into the userform) so that I can use the form

in
several different subs.

My other problem, and the one that I mentioned in my

first
posting, is that I want it to do nothing if the Cancel
button was the way out of the userform.

Sub Test()
ChooseCohort.Show
If ChooseCohort.CheckBoxER1.Value = True Then

MsgBox "ER1"
End Sub


-----Original Message-----
Adrian,

They would have separate click even ts so you can tell
that way.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the

Purbecks
(remove nothere from the email address if mailing

direct)

"Adrian" wrote in message
...
I have a custom dialogue that I need to use in two

very
different macros. Hence my OKButton_Click routine is
empty
except for Unload UserForm, so that the calling

macros
can
each do their own thing.

But how can the calling macros tell if it was the
OKbutton
or the Cancelbutton that was pressed?


.



.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Which button was pressed?

Yo,

puting

Me.Hide

in the ok buttons click event will hide the userform, but, and i'm
not sure i full understand what you are try to do, that not so good
for you, becasue you want to do diffrent things based on the choice
made on the userform,

Try this way:

some code to open the user form

YourFormName.Show

Now the form is open. It has all the option you might need on it. The
user chech on box or option and click ok.

now you must tell the programe what to do, based on what the user has
clicked so..

OKbutton_click

if optionbox1.value=true then
NameOfYourSubToGoTOIfThisCondtionIsPicked
elseif
AnotherSub
Else if

etc etc

'''Now close you form.

me.close

end sub


next time you open this form the last check box will still be checked,
but the sub will not run unless the user pressess OK


Good Luck

ROss
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
create a button when pressed it will +1 to another field mswisher Excel Discussion (Misc queries) 2 November 24th 09 04:34 PM
Enter button jumps to next cell each time its pressed!!!! evasmagacz Excel Discussion (Misc queries) 3 June 17th 07 08:37 PM
preventing button being pressed Mike Excel Discussion (Misc queries) 2 March 16th 06 03:47 PM
count how many times a button is pressed Mike Excel Discussion (Misc queries) 2 February 5th 06 09:38 PM
Errormessage when button is pressed twice or more Pointerman Excel Programming 4 April 7th 04 03:56 PM


All times are GMT +1. The time now is 08:25 PM.

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"