Solved

4 Checkboxes Selected Captions should be Displayed in Textbox

Posted on 2011-02-27
1
361 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
Comment Utility
    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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now