Solved

4 Checkboxes Selected Captions should be Displayed in Textbox

Posted on 2011-02-27
1
362 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

832 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