Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

form Controls change in excel

Posted on 2012-04-10
9
Medium Priority
?
275 Views
Last Modified: 2012-04-16
Hello All,
I currently have all checkboxes in the worksheet that use auto filter to filter and copy data to another sheet. Everything is working all right. I just need to make a change. The checkboxes that refer to the M series like M1,M2,M3,M4,M5 needs to be in button mode, Not in checkboxes
.. and the Rest of the checkboxes remain the way they are. And the filtering happens  just the same
Now to change that in vba – for each controls in the worksheet, filter accordingly - can anyone help?
Attached file….

Thank you
R
somecheckboxes2ButtonsLoop.xlsm
0
Comment
Question by:Rayne
  • 5
  • 4
9 Comments
 
LVL 42

Accepted Solution

by:
dlmille earned 2000 total points
ID: 37829699
Do you want command buttons or IN/OUT buttons (which work like checkboxes) for the M-Series?

With buttons, I assume you want them ON or OFF based on the push of the button.

we just create macros against each button like:

    [m123_Range].Columns(2).Cells(1).Value = IIf([m123_Range].Columns(2).Cells(1).Value = 1, 0, 1)
    Call doFilterGetResults
End Sub

and then comment out the test for the M1-M5 checkbox in the loop.

See attached.

With In/Out buttons, the behavior would be more like with checkboxes.  With push buttons, its hard to visibly show the "state" that the button push would be in.

Let me know if this is what you're looking for or if you want to try the IN/OUT buttons.

Dave
somecheckboxes2ButtonsLoop-r1.xlsm
0
 

Author Comment

by:Rayne
ID: 37829760
Hello Dave,

Thank you for replying :)
I need need command buttons for this.

R
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37829767
Ok - that's what you got.  Check it out and see if the behavior is what you want.

Dave
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Rayne
ID: 37829800
Hello Dave,
If you can demo the push button, I can take a look – yes it would make more sense to see the state in which the section is..
Yes, that makes a lot of sense - With push buttons; it’s hard to visibly show the "state" that the button push would be in.
Users will first filter the data by M series and then sub filter them by the other checkboxes

R
0
 

Author Comment

by:Rayne
ID: 37829901
Thanks again Dave for your quick help. The command button works great. If you have time and this is less complex, then you may post the in / out button and I can take a look.
R
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37830000
There's a couple ways to do this.  The push buttons are activeX controls (so caveats about using them in worksheets.  While I do, some folks have quirky resize problems, so most MVPs will tell you not to use them except in userforms).

Moving on...

1.  Could create a click event for each button toggled, and do work from there,
2.  Or, do it in the script we already have, and just check the state of the push button.

Since we have to have event code anyway when the toggle happens, I'm doing it via #1, above, so will be similar to the command button routine.

so in the MainViewSheet codepage we have code like this:

Private Sub TB_1_Click()
    [m123_Range].Columns(2).Cells(1).Value = IIf(TB_1.Value = -1, 1, 0)
    Call doFilterGetResults
End Sub

Open in new window


And for initialize we have added code like this:
Sub CBInitialize(wks As Worksheet)
Dim cBox As CheckBox
Dim objOLE As OLEObject

    'initialize all CheckBoxes to FALSE
    For Each cBox In wks.CheckBoxes
        If Left(UCase(cBox.Name), 2) = "CB" Then
            cBox.Value = False
        End If
    Next cBox

    'initialize all toggle buttons to FALSE
    For Each objOLE In wks.OLEObjects
        If objOLE.progID = "Forms.ToggleButton.1" And Left(objOLE.Name, 2) = "TB" Then
            objOLE.Object.Value = False
        End If
    
    Next objOLE
    
    Call clearMain(wks)
    
End Sub

Open in new window


We check the name as with check boxes, to ensure we don't change toggle buttons or check boxes we don't want to - there could be others we DON'T want to use with the filtering, which is why we named them in the first place ;)


PS - at some point, you'll want to know how to do an event or change based on a change to ANY control, without having to create a function/subroutine STUB for each control as we have done in this workbook.  When you're ready, ask that question as there are classes that can be developed that check for clicks all in one set of code.

Dave
somecheckboxes2ButtonsLoop-r2.xlsm
0
 

Author Comment

by:Rayne
ID: 37830250
Hello Dave,

That is great. This button looks way better than the other one and shows the state – that’s perfect. Yes, I will ask that question next for the event handling. Way less code than what I have got now :)


R
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37849457
Here's a tip - instead of assigning a new macro to each checkbox (which in turn calls the same macro) just have each checkbox call the main macro that needs to be called.

Not sure why I didn't point that out, earlier.

Just have all the checkboxes that end up calling doFilterGetResults() just linked to doFilterGetResults() rather than a _Click macro that calls doFilterGetResults().

Cheers,

Dave
0
 

Author Comment

by:Rayne
ID: 37854528
Hello Dave,

I have posted two questions in EE

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Q_27678921.html
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Q_27678898.html

When you have time, you may take a look. I have attached files in both cases.

Thank you :)

R
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

782 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