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.
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.