PC Review


Reply
Thread Tools Rate Thread

Clearing option buttons

 
 
CB
Guest
Posts: n/a
 
      19th Mar 2009
Hello,

I’m trying to determine how to clear the option buttons on my worksheet for
the instance when the user first goes to the given page. I figure that if
they are blank, the user will realize that nothing has been selected so they
have to select something. I read the post “Set OptionBox Value via VBA”
posted earlier today and tried the using Chip’s suggestions in the
Workbook_Activate() procedure (thinking these would be “default” values”) but
kept getting various types of errors. I don’t even remember what anymore –
my head is spinning….

A little more info for you…

My workbook has two sheets, “Pre-Service” and “Post-Service.” The second
sheet contains six option buttons (added using the Control Toolbox) set up as
three groups of two buttons. Each group has a YES button and a NO button. I
haven’t linked the buttons to a particular cell via the properties, but I do
have code that will put a YES or NO in a given cell depending on which button
in the group was clicked. I’ve included the code below to help clarify what I
mean. I’m not sure it’s that efficient but it works.

Private Sub DesiccantYes_Click()
Worksheets("Post-Service").Range("N4") = "Yes"
End Sub
Private Sub DessicantNo_Click()
Worksheets("Post-Service").Range("N4") = "No"
End Sub
Private Sub OringYes_Click()
Worksheets("Post-Service").Range("N5") = "Yes"
End Sub
Private Sub OringNo_Click()
Worksheets("Post-Service").Range("N5") = "No"
End Sub
Private Sub TransducerYes_Click()
Worksheets("Post-Service").Range("N6") = "Yes"
End Sub
Private Sub TransducerNo_Click()
Worksheets("Post-Service").Range("N6") = "No"
End Sub

Thanks again!

Chris

 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      20th Mar 2009
Hi Chris,

You can just set all the option buttons to false with code. The following
code if placed in ThisWorkbook module will set them all to false when the
workbook is activated.

Not sure if you know this but just in case. The option button name and the
option button caption are 2 different properties. When you open properties,
the name is the first property and is used in code to identify the button.
The caption is simply what you see on the screen and while it defaults to the
button name when created, you do not use it to identify the button in code.

If you have changed the option button names from the default names then you
will need to edit the names in the following code.

Private Sub Workbook_Activate()

With Sheets("Post-Service")
.OptionButton1 = False
.OptionButton2 = False
.OptionButton3 = False
.OptionButton4 = False
.OptionButton5 = False
.OptionButton6 = False
End With

End Sub

--
Regards,

OssieMac


"CB" wrote:

> Hello,
>
> I’m trying to determine how to clear the option buttons on my worksheet for
> the instance when the user first goes to the given page. I figure that if
> they are blank, the user will realize that nothing has been selected so they
> have to select something. I read the post “Set OptionBox Value via VBA”
> posted earlier today and tried the using Chip’s suggestions in the
> Workbook_Activate() procedure (thinking these would be “default” values”) but
> kept getting various types of errors. I don’t even remember what anymore –
> my head is spinning….
>
> A little more info for you…
>
> My workbook has two sheets, “Pre-Service” and “Post-Service.” The second
> sheet contains six option buttons (added using the Control Toolbox) set up as
> three groups of two buttons. Each group has a YES button and a NO button. I
> haven’t linked the buttons to a particular cell via the properties, but I do
> have code that will put a YES or NO in a given cell depending on which button
> in the group was clicked. I’ve included the code below to help clarify what I
> mean. I’m not sure it’s that efficient but it works.
>
> Private Sub DesiccantYes_Click()
> Worksheets("Post-Service").Range("N4") = "Yes"
> End Sub
> Private Sub DessicantNo_Click()
> Worksheets("Post-Service").Range("N4") = "No"
> End Sub
> Private Sub OringYes_Click()
> Worksheets("Post-Service").Range("N5") = "Yes"
> End Sub
> Private Sub OringNo_Click()
> Worksheets("Post-Service").Range("N5") = "No"
> End Sub
> Private Sub TransducerYes_Click()
> Worksheets("Post-Service").Range("N6") = "Yes"
> End Sub
> Private Sub TransducerNo_Click()
> Worksheets("Post-Service").Range("N6") = "No"
> End Sub
>
> Thanks again!
>
> Chris
>

 
Reply With Quote
 
CB
Guest
Posts: n/a
 
      20th Mar 2009
Hi OssieMac,

Thanks for taking the time to help. Your code worked like a charm.

At first I got a run-time error then I realized I had a rotten typo - the
same thing that gave me problems when I tried Chip's suggestions. Sheesh! I
should stay away from this machine when I'm tired. I ended up wasting several
hours.

Anyway, thanks again!

Chris

"OssieMac" wrote:

> Hi Chris,
>
> You can just set all the option buttons to false with code. The following
> code if placed in ThisWorkbook module will set them all to false when the
> workbook is activated.
>
> Not sure if you know this but just in case. The option button name and the
> option button caption are 2 different properties. When you open properties,
> the name is the first property and is used in code to identify the button.
> The caption is simply what you see on the screen and while it defaults to the
> button name when created, you do not use it to identify the button in code.
>
> If you have changed the option button names from the default names then you
> will need to edit the names in the following code.
>
> Private Sub Workbook_Activate()
>
> With Sheets("Post-Service")
> .OptionButton1 = False
> .OptionButton2 = False
> .OptionButton3 = False
> .OptionButton4 = False
> .OptionButton5 = False
> .OptionButton6 = False
> End With
>
> End Sub
>
> --
> Regards,
>
> OssieMac
>
>
> "CB" wrote:
>
> > Hello,
> >
> > I’m trying to determine how to clear the option buttons on my worksheet for
> > the instance when the user first goes to the given page. I figure that if
> > they are blank, the user will realize that nothing has been selected so they
> > have to select something. I read the post “Set OptionBox Value via VBA”
> > posted earlier today and tried the using Chip’s suggestions in the
> > Workbook_Activate() procedure (thinking these would be “default” values”) but
> > kept getting various types of errors. I don’t even remember what anymore –
> > my head is spinning….
> >
> > A little more info for you…
> >
> > My workbook has two sheets, “Pre-Service” and “Post-Service.” The second
> > sheet contains six option buttons (added using the Control Toolbox) set up as
> > three groups of two buttons. Each group has a YES button and a NO button. I
> > haven’t linked the buttons to a particular cell via the properties, but I do
> > have code that will put a YES or NO in a given cell depending on which button
> > in the group was clicked. I’ve included the code below to help clarify what I
> > mean. I’m not sure it’s that efficient but it works.
> >
> > Private Sub DesiccantYes_Click()
> > Worksheets("Post-Service").Range("N4") = "Yes"
> > End Sub
> > Private Sub DessicantNo_Click()
> > Worksheets("Post-Service").Range("N4") = "No"
> > End Sub
> > Private Sub OringYes_Click()
> > Worksheets("Post-Service").Range("N5") = "Yes"
> > End Sub
> > Private Sub OringNo_Click()
> > Worksheets("Post-Service").Range("N5") = "No"
> > End Sub
> > Private Sub TransducerYes_Click()
> > Worksheets("Post-Service").Range("N6") = "Yes"
> > End Sub
> > Private Sub TransducerNo_Click()
> > Worksheets("Post-Service").Range("N6") = "No"
> > End Sub
> >
> > Thanks again!
> >
> > Chris
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing Option Buttons pdaws Microsoft Excel Misc 3 25th Mar 2009 09:10 PM
VBA - Delay in clearing option buttons John Michl Microsoft Powerpoint 5 18th Feb 2009 05:40 PM
Binding Values from a Table to Option Buttons contained in an Option Group faerewing@gmail.com Microsoft Access 3 15th Jan 2007 10:01 PM
Clearing Option Buttons =?Utf-8?B?ZHNpbWNveA==?= Microsoft Excel Programming 1 2nd Dec 2004 09:16 PM
Clearing Option Buttons Rod Microsoft Excel Misc 3 19th Feb 2004 12:38 AM


Features
 

Advertising
 

Newsgroups
 


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