Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Toggle choices within a user form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
richardb - 10 Oct 2005 21:00 GMT
I have introduced a user form within a macro with two check boxes to give
users a choice. I want Selection of one check box to deselect the other
(without writing a lot of code to do this). I tried placing the check boxes
within a frame, hoping this would behave as with Access VBA. I also tried to
assign both check boxes to the same GroupName (which was also the name of the
frame) both in the property window and using code in the UserFrom Activate
Sub. These did not work and I could not find better on-line help.  I would
appreciate someone's help with this. Thank you.
Marc Adams [marcmyword.com] - 10 Oct 2005 21:39 GMT
If you have two checkboxes only:

Private Sub CheckBox1_Click()
   Me.CheckBox2.Value = Not Me.CheckBox1.Value
End Sub

Private Sub CheckBox2_Click()
  Me.CheckBox1.Value = Not Me.CheckBox2.Value
End Sub

Basically when one checkbox is on, it evaluates to the opposite of the other
textbox.

Hope this helps.

Signature

Please visit my new site: www.marcmyword.com. I would love your input as to
how to make it great.

> I have introduced a user form within a macro with two check boxes to give
> users a choice. I want Selection of one check box to deselect the other
[quoted text clipped - 4 lines]
> Sub. These did not work and I could not find better on-line help.  I would
> appreciate someone's help with this. Thank you.
richardb - 10 Oct 2005 23:54 GMT
Thank you. That works for two choices, but I was hoping for something that
works more like Access, where a frame takes on the value of alternate choices
within.

> If you have two checkboxes only:
>
[quoted text clipped - 19 lines]
> > Sub. These did not work and I could not find better on-line help.  I would
> > appreciate someone's help with this. Thank you.
Jay Freedman - 11 Oct 2005 00:43 GMT
Is there a reason you're using check boxes instead of option buttons,
which normally behave exclusively?

A frame in a userform doesn't take on the value of anything -- it
doesn't even have a .Value property -- but you can use it as a
container. If you put any number of option buttons in a frame on a
userform, you can run code similar to this:

Private Sub CommandButton1_Click()
   Dim i As Integer
   For i = 0 To Frame1.Controls.Count - 1
       If Frame1.Controls(i).Value Then
           ' do something with the selected one
           MsgBox Frame1.Controls(i).Caption
    Exit For
       End If
   Next i
   Unload Me
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org

>Thank you. That works for two choices, but I was hoping for something that
>works more like Access, where a frame takes on the value of alternate choices
[quoted text clipped - 23 lines]
>> > Sub. These did not work and I could not find better on-line help.  I would
>> > appreciate someone's help with this. Thank you.
richardb - 11 Oct 2005 14:29 GMT
Jay, I should have referred to an "Option Group" as in Access, not a frame. I
don't find an option group in Word VBA. I also have not figured out how to
put toggle buttons on a user form so they alternate. I'd be grateful for a
tip and otherwise the solutions already provided will work nicely thank you.

> Is there a reason you're using check boxes instead of option buttons,
> which normally behave exclusively?
[quoted text clipped - 48 lines]
> >> > Sub. These did not work and I could not find better on-line help.  I would
> >> > appreciate someone's help with this. Thank you.
Jay Freedman - 11 Oct 2005 16:30 GMT
There isn't an "option group" control in Word VBA as such, but there are two
ways to create something that works the same way. They're described in the
VBA Help topic "
Ways to create an option group
". One way is to use a frame, together with code like that I already showed.
The other way is to use the GroupName property of each option button.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Jay, I should have referred to an "Option Group" as in Access, not a
> frame. I don't find an option group in Word VBA. I also have not
[quoted text clipped - 60 lines]
>>>>> on-line help.  I would appreciate someone's help with this. Thank
>>>>> you.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.