Solved

4 Checkboxes Selected Captions should be Displayed in Textbox

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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.
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

622 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