Solved

4 Checkboxes Selected Captions should be Displayed in Textbox

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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…

756 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