Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aquiring message box responses

Status
Not open for further replies.

Westicle

Programmer
Aug 22, 2002
29
GB
What would be a standard way to return which button someone has pressed. I.E:

I have an OK/Cancel button and if the user presses OK the page is printed. How do i get there response so i can then do
(Code)
If response = OK Then
Sheet1.PrintOut
End If


Thanks.
 
I assume the button is on a form you activated with its "show" method on a previous line of code? A straightforward way of passing the response back would be with a public variable:

public PrintIt as boolean
...

sub OKButton_click()
...
PrintIt=true
unload me
end sub()

sub userform_activate()
...
PrintIt=false
end sub()

If you don't like public variables, you can instead use the "tag" property of your OKButton:

sub OKButton_click()
...
OKButton.tag="clicked"
me.hide
end sub()

...
MyForm.Show
if MyForm.OKButton.tag="clicked" then
...
end if
Myform.Unload

Note you can't unload the form in this case until you've checked the button status.
I'm sure there are many other solutions.
Rob
 
just set a variable to get the msgbox return value:


sub tranpkp()
d = MsgBox("WHICH?", vbYesNoCancel, "TRANPKP")
If d = vbYes Then
MsgBox ("YES")
End If

end sub
[/green]

[yinyang] Tranpkp [pc2]
************************************
- Let me know if this helped/worked!
Please remember to give helpful posts the stars they deserve!
This facilitates others navigating through the threads / posts!
 
Oh yes - I see now, you simply need a messagebox return value. Silly me - ignore my previous message...
Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top