Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Retain value of userform option button

I have a simple user form with three option buttons. I would like the
value(true or false) of the option buttons to remain the same before
the userform is unloaded. I thought I would store the value in a cell
on the spreadsheet with the following code:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
Sheets("sheet1").Range("f1") = OptionButton1.Value
End Sub

But the ob value is always false when the userform is reloaded, even
though it was true when unloaded. Does anyone have a way to do this?

Thanks in advance for any advice!

Greg
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Retain value of userform option button


What is it you are trying to achieve?, what would retaining the last
clicked value do for you?

Gig;269824 Wrote:
I have a simple user form with three option buttons. I would like the
value(true or false) of the option buttons to remain the same before
the userform is unloaded. I thought I would store the value in a cell
on the spreadsheet with the following code:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
Sheets("sheet1").Range("f1") = OptionButton1.Value
End Sub

But the ob value is always false when the userform is reloaded, even
though it was true when unloaded. Does anyone have a way to do this?

Thanks in advance for any advice!

Greg



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=75235

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Retain value of userform option button

Have you got the command OptionButton1.Value = Sheets("sheet1").Range("f1")
in the UserForm_Open procedure?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Retain value of userform option button

Place this code behind your form - it should do what you are looking for:

Private Sub UserForm_Initialize()
Dim ctl As Control
Dim CtrlType As String
'change Userform1 to name of your form
For Each ctl In UserForm1.Controls

CtrlType = TypeName(ctl)

If CtrlType = "OptionButton" Then

ctl.Value = GetSetting(AppName:="MyApp", _
section:="UserForm Settings", _
key:=ctl.Name, Default:=False)

End If
Next ctl
End Sub


Private Sub UserForm_Terminate()
Dim ctl As Control
Dim CtrlType As String
'change Userform1 to name of your form
For Each ctl In UserForm1.Controls

CtrlType = TypeName(ctl)

If CtrlType = "OptionButton" Then

SaveSetting AppName:="MyApp", _
section:="UserForm Settings", _
key:=ctl.Name, setting:=CStr(ctl.Value)

End If
Next ctl
End Sub

--
jb


"Gig" wrote:

I have a simple user form with three option buttons. I would like the
value(true or false) of the option buttons to remain the same before
the userform is unloaded. I thought I would store the value in a cell
on the spreadsheet with the following code:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
Sheets("sheet1").Range("f1") = OptionButton1.Value
End Sub

But the ob value is always false when the userform is reloaded, even
though it was true when unloaded. Does anyone have a way to do this?

Thanks in advance for any advice!

Greg

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 762
Default Retain value of userform option button

Greg -

In addition to storing the value somewhere, you also need to use the user
form Initialize event to use that value (if it has been defined) to set the
option buttons before you Show the user form.

And, you need to use Show and Unload to trigger Initialize and QueryClose,
not Hide (which won't trigger the QueryClose event).

By the way, I typically use a hidden defined name (instead of a worksheet
cell) to store this kind of data.

- Mike

http://www.MikeMiddleton.com



"Gig" wrote in message
...
I have a simple user form with three option buttons. I would like the
value(true or false) of the option buttons to remain the same before
the userform is unloaded. I thought I would store the value in a cell
on the spreadsheet with the following code:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
Sheets("sheet1").Range("f1") = OptionButton1.Value
End Sub

But the ob value is always false when the userform is reloaded, even
though it was true when unloaded. Does anyone have a way to do this?

Thanks in advance for any advice!

Greg



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
Populate userform combobox with option button Gig[_2_] Excel Programming 3 March 12th 09 06:05 PM
option button and userform question Shawn Excel Programming 1 June 29th 07 12:51 AM
need help on how to grey out one option button in one group box based on the selection of another option button in another group box George Excel Programming 12 March 11th 07 02:08 PM
Userform retain data after closing and reopening Joel Mills Excel Programming 4 June 20th 05 08:57 PM
Global value does not retain value when UserForm is hide Alex[_15_] Excel Programming 1 November 4th 03 10:03 AM


All times are GMT +1. The time now is 08:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"