?
Solved

Working With Checkbox in VBA Excel

Posted on 2011-03-06
5
Medium Priority
?
1,022 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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