PDA

View Full Version : Dynamic sliders in a userform



n8Mills
12-20-2008, 12:08 AM
Hey all (again)!

I've created a userform (as mentioned in previous posts) that populates controls dynamically. The following statement doesn't work as it does with textboxes, checkboxes, etc.
Set sliderClass(sliderNum - 1).mySlider = Me.Controls.Add("Forms.Slider.1", "slider" & sliderNum) It throws a "Invalid class string" error, which I believe pertains to the "Forms.Slider.1" portion of the statement, or maybe even everything after the "=" there. The Slider ActiveX Control 6.0 (SP6) is not part of the MSForms Object Library, so I believe I need a different statement to add it to the userform. I'm also considering whether I need to add the reference in the "Tools" menu.

I believe I'm on the right track as Intellisense was prompting me with the properties in the following With block:

With sliderClass(sliderNum - 1).mySlider
.Top = 48 + (sliderNum * 18)
.Width = 204
.Height = 12
.Left = 72
.Value = Range("slider" & sliderNum)
.Max = Evaluate("=SUM(allCells)")
.SmallChange = .Max / 100
.LargeChange = .Max / 20
.TickFrequency = .Max / 10
End With
Any thoughts on how to add the sliders to my userform? (All the code is the in form within the attached example.)

Thanks,

Nate

lucas
12-20-2008, 11:03 AM
Adding controls on the fly is problematical as you are finding out. You not only have to add the controls on the fly you have to create the code to run it....on the fly. I don't understand the need for doing that. Can you explain why it is absolutely necessary?


May I suggest an alternative. Maybe have the controls on the userform but have them hidden until you need them.

There are several ways to do that and one is to have an expanding userform where hidden controls can be shown or hidden as in the example attached.

You of course could just hide them and show them when you need them too without using an expanding userform.

n8Mills
12-20-2008, 11:55 AM
Hi Lucas,

Thanks for that idea, I like the "animated window" expansion/contraction, it's pretty clever.

After I posted this question I searched some more and found a page where somebody listed the use of scrollbars in place of sliders, which I adopted. I had to change the code somewhat, but it's working.

I like the aesthetics of the sliders much better, but until somebody points out how to add ActiveX controls I'll stick with this method.

Thanks for the look!

Nate