Syntax Problem : Grouping Buttons On A Multipage

D

donna.gough

Folkes,
These are my declarations...

Dim TempForm1
Dim Form1 As MultiPage
Dim ctrl As Control
Dim NextColl As Collection

Set TempForm1 = ThisWorkbook.VBProject.VBComponents.Add(3)
Set Form1 = TempForm1.designer.Controls.Add("forms.MultiPage.1")

.....on each of my multipage tabs I have a button with the name
"Next1","Next2" etc and it's these I want to group together so I can
write 1 sub for all the next buttons. This is the code I am trying to
use to group those buttons....

For Each ctrl In UserForm1.Controls
If Left(ctrl.Name, 4) = "Next" Then NextColl.Add Item:=ctrl
Next ctrl

....I have 2 problems.

1.) Initially I have to change UserForm1 to Userforms otherwise it
errors saying that the variable (UserForm1) is not declared. But when
it executes, it stops at this line with the error 'Object does not
support this property or method', so I debug it back to UserForm1 and
the for/next loop works...WHAT SHOULD THE FOR EACH LINE BE ?

2.) It loops the controls, find a "Next" but then won't add it to my
NextColl....WHAT SHOULD THIS LINE BE ? I think I'm missing a Set
NextColl=??????, am I ?

Thanks for any help you can give me.
 
D

donna.gough

Problem 1 still stands....can anybody please help. Syntax for the ' FOR
EACH ' line.

Problem 2 solved by changing to ' Dim NextColl As New Collection '.

-> Next Problem !....I can get my collection of commandbuttons
(NextColl), but how to reference it in the .CreateEventProc ?
.........The code below does not work.

With TempForm1.CodeModule
X = .CreateEventProc("Click", NextColl)
..InsertLines X + 1, "MultiPage1.Value = MultiPage1.Value + 1"
End With
 

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