Solved

4 Checkboxes Selected Captions should be Displayed in Textbox

Posted on 2011-02-27
1
365 Views
Last Modified: 2012-05-11
I have 4 Check Boxes in my Form, when the user selects more than one Checkbox and click on Command Button, the concatenated result of all Checkbox captions should be displayed in Textbox with "Or" in between each

If he selects only One, than Selected Checkbox caption only should be displayed without any "Or" , as he has selected only one checkbox


Below is my Code, what changes should be made to solve the above purpose,

Dim strMsg As String
    If Me.CheckBox1 Then strMsg = strMsg & CheckBox1.Caption
    If Me.CheckBox2 Then strMsg = strMsg & " Or " & CheckBox2.Caption
    If Me.CheckBox3 Then strMsg = strMsg & " Or " & CheckBox3.Caption
    If Me.CheckBox4 Then strMsg = strMsg & " Or " & CheckBox4.Caption
    If Len(strMsg) = 0 Then
        MsgBox "You should select any one value!'"
    Else
        TextBox1.Value = strMsg
    End If


Problem with the above code is, if the user selects only second Checkbox than the result displayed in the Textbox is- Or Checkbox2 Caption
0
Comment
Question by:srikanthv2322
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
ID: 34991695
    Dim strMsg As String
    
    
    If Me.CheckBox1 Then strMsg = strMsg & CheckBox1.Caption & " Or "
    If Me.CheckBox2 Then strMsg = strMsg & CheckBox2.Caption & " Or "
    If Me.CheckBox3 Then strMsg = strMsg & CheckBox3.Caption & " Or "
    If Me.CheckBox4 Then strMsg = strMsg & CheckBox4.Caption & " Or "
    If Len(strMsg) = 0 Then
        MsgBox "You should select any one value!'"
    Else
        TextBox1.Text = Left(strMsg, Len(strMsg) - 4)
    End If

Open in new window

0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question