ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   checkboxes and option buttons (https://www.excelbanter.com/excel-programming/306521-checkboxes-option-buttons.html)

Tim[_39_]

checkboxes and option buttons
 
XP pro, xl2002

hi i have a userform with several checkboxes. if any of them are checked i
want their captions to be concatenated together with some text in a textbox
to be transferred together into another textbox at the click of a button.

eg, textbox1 = "TVC"
checkbox1 = checked (caption "-1")
checkbox2 = unchecked (caption "-2")
checkbox3 = checked (caption "-3")

so, textbox2 would = "TVC-1-3"

i CAN do all of this, but want to know if there is an efficient way of
working through each checkbox (of which there are 7)

subsequently, a smilar solution for the optionbuttons (although, obviously
only one will be 'true')

in addition (if it makes a difference), all the checkboxes are in one frame
and the option buttons in another frame - these are bth enclosed in another
frame... currently for aesthetic purposes, but don't know if it makes any
difference to what i want to achieve. can i refer to all objects enclosed in
a frame?

thanks all,

tim



Dave Peterson[_3_]

checkboxes and option buttons
 
If your checkboxes are nicely named: checkbox1 through checkbox7, then maybe
something like:

Option Explicit
Private Sub CommandButton1_Click()

Dim iCtr As Long
Dim myStr As String

myStr = Me.TextBox1.Value
For iCtr = 1 To 7
With Me.Controls("checkbox" & iCtr)
If .Value = True Then
myStr = myStr & .Caption
End If
End With
Next iCtr

Me.TextBox2.Value = myStr

End Sub



Tim wrote:

XP pro, xl2002

hi i have a userform with several checkboxes. if any of them are checked i
want their captions to be concatenated together with some text in a textbox
to be transferred together into another textbox at the click of a button.

eg, textbox1 = "TVC"
checkbox1 = checked (caption "-1")
checkbox2 = unchecked (caption "-2")
checkbox3 = checked (caption "-3")

so, textbox2 would = "TVC-1-3"

i CAN do all of this, but want to know if there is an efficient way of
working through each checkbox (of which there are 7)

subsequently, a smilar solution for the optionbuttons (although, obviously
only one will be 'true')

in addition (if it makes a difference), all the checkboxes are in one frame
and the option buttons in another frame - these are bth enclosed in another
frame... currently for aesthetic purposes, but don't know if it makes any
difference to what i want to achieve. can i refer to all objects enclosed in
a frame?

thanks all,

tim


--

Dave Peterson



All times are GMT +1. The time now is 05:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com