Specifying Item number of control on user form

M

Mark Stephens

I have a number of controls on my user form and am cycling through them. The
problem I have is that whenever I decide to add a new member to the group
(frequently) it is given the item number according to the order it waqs
placed on the page (i.e. if it is the 50th control number 50) when I want it
to be (for exxample) number 10 since it an addition to an existing 1-9
option buttons and I want to cycle them.

Sure I can cut every other control and repaste it and then the item number
is as i want it but hopefully there is a more elegant solution ... anyone?

Thanks and regards, Mark
 
R

Rick Rothstein

What did you want to do with the OptionButtons currently numbered 10, 11,
12, etc. then? If you automatically bump their number's up, wont' that screw
up your code? Why aren't you using the GroupName property to group your
controls (then the numbers wouldn't matter)? I presume when you say "cycle
them", I presume you mean 'in code'. You would do that by examining the
GroupName in your loop. For example, if the GroupName for one grouping of
OptionButtons was "MyFirstGroup", then you could cycle each one with code
like this...

Dim C As Control
For Each C In Me.Controls
If TypeOf C Is msForms.OptionButton Then
If C.GroupName = "MyFirstGroup" Then
Debug.Print C.Name
End If
End If
Next
 
P

Peter T

Just to add, it is not possible to re-order index number of a controls on a
Userform. That means when you add a new control its index will be
controls.count - 1 (as the first is zero). If you delete a control all
subsequent index's will decrease correspondingly. No way to change that.

You can build a form entirely with code to the form's "designer" object. For
example, you could lay out all your details & properties in a table, add,
amend, sort, etc, and go from there. But probably better to follow Rick's
advice unless you want another learning curve !

Regards,
Peter T
 
T

Tim Zych

Another option is to add controls at runtime instead. If you are adding
controls as frequently as seems to suggest, it will give you a great deal of
flexibility and power. It's a big difference from how you are doing it now,
but it can take your project to a higher level.
 
M

Mark Stephens

Hi Tim/aa,

Thanks for your suggestions....Tim's idea of adding at runtime seems to be a
good option, it shouldn't be too much extra work and as you say it wil
give me flexibility (actually I could for example have a sheet with column a
containing button captions, and have a routine count the number and name
them accordingly, that way I can change a lot). Thanks for the suggestion,
regards, Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top