WithEvents question AND loading controls at runtime question

P

Patrick Pirtle

I have two groups of users who will be working with
my app. My app has a multipage control with 8
pages. Each page may have up to 30 controls.
User group #1 needs pages 1-4 and their own
set of pages 5-8. User group #2 needs pages
1-4 and their own set of pages 5-8.

At first, I tried hiding the pages each group didn't
need. However, I was getting memory errors.
Someone explained that a form can't have more
than 256 controls. So, I separated the app into
2 user-group-specific apps. Unfortunately, this
means that I have to maintain pages 1-4 in each
app. Ugh!

Therefore, I'm trying to figure out how to merge
pages 1-4 into each of the two apps, OR, how
my SINGLE app might contain 3 userforms.
One that contains the shared pages 1-4, and
2 others that contain the user-specific pages 5-8.
These, then, could be merged at runtime depending
on which group is using the app.


In my test scenario below, I'm trying to copy the
single page from Userform2 to Userform1 along
with it's controls:

1. "Userform1" contains:
- "MultiPage1" - multi-page control with (1) page
- "CommandButton1"

2. "Userform2" contains
- "tabMKA" - multi-page control with (1) page
- tabMKA.Pages(0) contains "btnMKA" (command
button control)

Here's the code from Userform1:

'=================Begin================
Private Sub CommandButton1_Click()
Dim newPage As Page
Dim nPages As Long

With Me.MultiPage1
nPages = .Count
Set newPage = .Pages.Add("Page" & (nPages + 1), _
"Address " & (nPages + 1), nPages)
newPage.Caption = UserForm2.tabMKA.Pages(0).Caption
End With

UserForm2.tabMKA.Pages(0).Controls.Copy
newPage.Paste

Set UserForm2 = Nothing

End Sub

Private Sub btnMKA_Click()
MsgBox "OK"
End Sub
'=================End==================



And finally, here are my questions:

1. This code DOES copy btnMKA and pastes it to the
newly-inserted page in Userform1. However, the code
for btnMKA_Click doesn't run--I suppose because VB
doesn't have a "btnMKA" when it's compiled. (?) How
can I link my pasted button to the appropriate code?

2. The helpful person who originally steered me down this
road of inquiry suggested I make use of WithEvents to
handle many more controls than the allowed 256. I have
been looking up WithEvents on the net, but have NO idea
how this might apply to my problem.

How could I use WithEvents to handle the code for a
large quantity of controls? Do the names of the controls
make any difference (i.e. "btn_MKA" instead of
"CommandButton1")?

3. Is the line "Set UserForm2 = Nothing" necessary, or
a good idea, or...?

Thanks, in advance, for any help or guidance you can
give me.
 
A

alpine

Have you tried making each of your pages a usercontrol? You could
also wrap your pages 1-4 in it's own usercontrol.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'(e-mail address removed) Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
 
P

Patrick Pirtle

Bryan -
Many thanks for your reply. Unfortunately, with my
limited knowledge of VB, I don't understand where to
start to understand your suggestion. I'll start doing some
Googling for "usercontrol" and see if I can get some
ideas. Any suggestions for where to start?
--------------------------------------------------------
The impossible just takes a little longer
Have you tried making each of your pages a usercontrol? You could
also wrap your pages 1-4 in it's own usercontrol.
[snip]
 
A

alpine

The first place to look is your VB help file. I'm assuming you're
working in VB6 since you've included the general.discussion group so,
you can add usercontrols to your project and then add the desired
controls to the usercontrols along with code to arrive at the behavior
you wish to exhibit.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'(e-mail address removed) Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


Bryan -
Many thanks for your reply. Unfortunately, with my
limited knowledge of VB, I don't understand where to
start to understand your suggestion. I'll start doing some
Googling for "usercontrol" and see if I can get some
ideas. Any suggestions for where to start?
--------------------------------------------------------
The impossible just takes a little longer
Have you tried making each of your pages a usercontrol? You could
also wrap your pages 1-4 in it's own usercontrol.
[snip]
 
P

Patrick Pirtle

alpine said:
The first place to look is your VB help file. I'm assuming you're
working in VB6 since you've included the general.discussion group so,
you can add usercontrols to your project and then add the desired
controls to the usercontrols along with code to arrive at the behavior
you wish to exhibit.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'(e-mail address removed) Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


Bryan -
Many thanks for your reply. Unfortunately, with my
limited knowledge of VB, I don't understand where to
start to understand your suggestion. I'll start doing some
Googling for "usercontrol" and see if I can get some
ideas. Any suggestions for where to start?
--------------------------------------------------------
The impossible just takes a little longer
Have you tried making each of your pages a usercontrol? You could
also wrap your pages 1-4 in it's own usercontrol.
[snip]
 
P

Patrick Pirtle

Alpine -
Thanks, once again, for your reply.

Just to make sure I'm not going down the wrong road--
Are you suggesting that I could MERGE a usercontrol
that contains pages 1-4 with another usercontrol that
contains pages 5-8 at runtime so that I end up with a
single multipage control with all 8 pages?

Or, should I create the multipage control in my app and
then create a separate usercontrol for the controls that
would be contained on each page?

I'm actually working on a VBA app, but have posted
to both newsgroups as was suggested by one of the
MVPs here. I suspect by your answer, and from the
lack of info in the help files or on the net, that VBA
doesn't support the CREATION of usercontrols.(?)
Am I correct, here? Should I be able to create the
control in VB6 and include it in my VBA project?
 
A

alpine

Actually, I'm suggesting that you do a little of both. You can create
a usercontrol for each of your pages 1-4 and then another usercontrol
that contains those "pages". You could then create other usercontrols
that contain other usercontrols for the other pages (5-xx).

You would need to create these in VB and then consume them in your VBA
project.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'(e-mail address removed) Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
 

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