[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Working With Checkbox in VBA Excel

Posted on 2011-03-06
5
Medium Priority
?
1,023 Views
Last Modified: 2012-05-11
I have four checkboxes in my VBA excel application which are as follows

ShowStopper
High
Medium
Low

I will be using this checkboxes to form an query to a database,

If the user selects all the checboxes, then the query that i am looking for should be like,

" ' 1 - Show Stopper' Or '2 - High' Or '3 - Medium' Or '4 - Low' "

How can i form this query line through the selection of  checkboxes

Please help with the coding, if you want i will change the caption of checkbox as 1 - Show Stopper' and as follows to form an query at last try only.


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
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 35047802
Hi there,

What kind of checkboxes are they?  Please be a bit more specific, as there are many types.  Is it a forms control?  An ActiveX control?  A userform control?  Tell us how you created it, and we'll know what kind it is.  Coding depends on the type.  And if you can tell us where/how you want to fire this, that would help.
0
 

Author Comment

by:srikanthv2322
ID: 35048033
Its a Form Control and i just created from selecting from Toolbox in VB
0
 
LVL 14

Accepted Solution

by:
Zack Barresse earned 2000 total points
ID: 35048092
You mean in the VBE?  Those are not forms controls, but ActiveX controls.  Or do you mean a forms control from the Excel environment, and wanting to use VBA on it?  What is your version of Excel?  Assuming you're using a userform from the VBE, you could use something like this...

    Dim sVar As String
    '" ' 1 - Show Stopper' Or '2 - High' Or '3 - Medium' Or '4 - Low' "
    If Me.CheckBox1.Value = True Then
        sVar = "'1 - Show Stoppper'"
    End If
    If Me.CheckBox2.Value = True Then
        sVar = IIf(Len(sVar) > 0, sVar & " Or '2 - High'", sVar)
    End If
    If Me.CheckBox3.Value = True Then
        sVar = IIf(Len(sVar) > 0, sVar & " Or '3 - Medium'", sVar)
    End If
    If Me.CheckBox4.Value = True Then
        sVar = IIf(Len(sVar) > 0, sVar & " Or '4 - Low'", sVar)
    End If
    MsgBox sVar

Open in new window


HTH
0
 

Author Comment

by:srikanthv2322
ID: 35049393
Small correction in the above code, from second Checkbox have the Caption intended in false statement of IIf and not sVar name.

0
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 35049432
You mean you want to have the check be opposite only for checkbox2?  Not sure I follow, but if that is correct, then...

    Dim sVar As String
    '" ' 1 - Show Stopper' Or '2 - High' Or '3 - Medium' Or '4 - Low' "
    If Me.CheckBox1.Value = True Then
        sVar = "'1 - Show Stoppper'"
    End If
    If Me.CheckBox2.Value = False Then
        sVar = IIf(Len(sVar) > 0, sVar & " Or '2 - High'", sVar)
    End If
    If Me.CheckBox3.Value = True Then
        sVar = IIf(Len(sVar) > 0, sVar & " Or '3 - Medium'", sVar)
    End If
    If Me.CheckBox4.Value = True Then
        sVar = IIf(Len(sVar) > 0, sVar & " Or '4 - Low'", sVar)
    End If
    MsgBox sVar

Open in new window


If that's not what you meant, can you clarify please?

Zack
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

656 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