Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default returning values from a User Form

I have user form with three option button so that the user can selec
one of the options.
How can I store the returned value in a variable?


Sub test()
Dim f1, f2, f3 As Boolean
UserForm1.Show
f1 = UserForm1.OptionButton1.Value
f2 = UserForm1.OptionButton2.Value
f3 = UserForm1.OptionButton3.Value
MsgBox f1 & f2 & f3
End Sub


Evertime I run this procedure I always get False, False, False (ie th
value set the properties section of the optionbutton).
I found a way to return the True if I select an option and false when
didn't but setting the ControlSource option of the properties sectio
to cell.
Is there a way I could get True when I select the optionand False whe
I don't wihtout setting the ControlSource to a cell, since then I hav
to have another Sheet that contains only the values from thes
optionsbuttons

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default returning values from a User Form

Sounds like you are UnLoading the userform, or allowing the user to dismiss
it with the close button, instead of using the Hide method to keep it in
memory. This means that control values are lost.

You can disable the Close button (the x in the top right of the form) by
trapping the QueryClose event and cancelling it by setting Cancel = True.
Force the user to use your own OK or Cancel button and use the Hide method
to close the userform.

John Green

"rohnds " wrote in message
...
I have user form with three option button so that the user can select
one of the options.
How can I store the returned value in a variable?


Sub test()
Dim f1, f2, f3 As Boolean
UserForm1.Show
f1 = UserForm1.OptionButton1.Value
f2 = UserForm1.OptionButton2.Value
f3 = UserForm1.OptionButton3.Value
MsgBox f1 & f2 & f3
End Sub


Evertime I run this procedure I always get False, False, False (ie the
value set the properties section of the optionbutton).
I found a way to return the True if I select an option and false when I
didn't but setting the ControlSource option of the properties section
to cell.
Is there a way I could get True when I select the optionand False when
I don't wihtout setting the ControlSource to a cell, since then I have
to have another Sheet that contains only the values from these
optionsbuttons.


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default returning values from a User Form

Suggested is that you make your variables Public and
declare them in a standard module. Use the UF Terminate
event to format the variable values.

In the UF code module:
Private Sub UserForm_Terminate()
f1 = OptionButton1.Value
f2 = OptionButton2.Value
f3 = OptionButton3.Value
End Sub

In a standard module:
Public f1 As Boolean
Public f2 As Boolean
Public f3 As Boolean

Sub GetOptBtnVals()
UserForm1.Show
MsgBox f1 & vbCr & f2 & vbCr & f3
End Sub

Regards,
Greg


-----Original Message-----
I have user form with three option button so that the

user can select
one of the options.
How can I store the returned value in a variable?


Sub test()
Dim f1, f2, f3 As Boolean
UserForm1.Show
f1 = UserForm1.OptionButton1.Value
f2 = UserForm1.OptionButton2.Value
f3 = UserForm1.OptionButton3.Value
MsgBox f1 & f2 & f3
End Sub


Evertime I run this procedure I always get False, False,

False (ie the
value set the properties section of the optionbutton).
I found a way to return the True if I select an option

and false when I
didn't but setting the ControlSource option of the

properties section
to cell.
Is there a way I could get True when I select the

optionand False when
I don't wihtout setting the ControlSource to a cell,

since then I have
to have another Sheet that contains only the values from

these
optionsbuttons.


---
Message posted from http://www.ExcelForum.com/

.

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
User Defined Function returning #Value! DogLover Excel Worksheet Functions 4 November 25th 09 07:31 PM
How do I fill a cell in a user form from a selection on same form? Terry Tipsy Excel Discussion (Misc queries) 4 June 11th 07 02:59 PM
Cell Values On User Form gregork Excel Programming 10 February 3rd 04 03:51 PM
I am looking to see if anybody has an equivalant user form to Outlooks CONTACT form BruceJ[_2_] Excel Programming 2 October 15th 03 05:28 PM
Returning User Initials Kelly[_3_] Excel Programming 10 August 11th 03 07:07 PM


All times are GMT +1. The time now is 02:23 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"