Referencing controls on a page of a multipage

Glowackattack

New Member
Joined
Mar 5, 2008
Messages
38
Hi All,
I have the following code in a module that works fine for referencing a textbox on a page of a multipage on a userform, but I'm stumped trying to figure out how to reference the page object itself vs the multipage then referencing the page later. My code is:

Code:
Dim a As MultiPage
    
    Set a = UserForm1.MultiPage1
    
    a.Page2.P2_ScoreTotal.Value = (Val(a.Page2.P2_Q1_Score.Text) + Val(a.Page2.P2_Q2_Score.Text) + Val(a.Page2.P2_Q3_Score.Text) + Val(a.Page2.P2_Q4_Score.Text)) / 4

what i want to do is something like this: (but doesnt work)

Code:
Dim a As (What? Page?)
    
    Set a = UserForm1.MultiPage1.Page2
    
    a.P2_ScoreTotal.Value = (Val(a.P2_Q1_Score.Text) + Val(a.P2_Q2_Score.Text) + Val(a.P2_Q3_Score.Text) + Val(a.P2_Q4_Score.Text)) / 4

I'm sure this is pretty simple but i'm having trouble figuring it out. Thanks!!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Code:
Dim a As Page
    
    Set a = UserForm1.MultiPage1.Pages(3)
    
    a.P2_ScoreTotal.Value = (Val(a.P2_Q1_Score.Text) + Val(a.P2_Q2_Score.Text) + Val(a.P2_Q3_Score.Text) + Val(a.P2_Q4_Score.Text)) / 4

or the With... End With:

Code:
    With UserForm1.MultiPage1.Pages(3)
         .P2_ScoreTotal.Value = (Val(.P2_Q1_Score.Text) + Val(.P2_Q2_Score.Text) + Val(.P2_Q3_Score.Text) + Val(.P2_Q4_Score.Text)) / 4
    End With
 
Upvote 0
Thanks for the reply. I tried using that with the name of the page ("Page2") instead of using the index and it wasnt working...do you have the syntax for using the name?
 
Upvote 0
If it's Page2 then probably it will be index value 1 instead of 3 (I added 1 instead of taking away 1).

If you'd like to use the name:

Code:
    With UserForm1.MultiPage1("Page2")
        MsgBox .Index
    End With
 
Upvote 0
I have the code below working just fine using the with statement, thanks for your help!!

Code:
    With UserForm1.MultiPage1.Page2
        .P2_ScoreTotal.Value = (Val(.P2_Q1_Score.Text) + Val(.P2_Q2_Score.Text) + Val(.P2_Q3_Score.Text) + Val(.P2_Q4_Score.Text)) / 4
    End With

but using the name when declaring a variable is not working as written below:

Code:
    Dim a As Page
    a = UserForm1.MultiPage1("Page2")
    a.P2_ScoreTotal.Value = (Val(a.P2_Q1_Score.Text) + Val(a.P2_Q2_Score.Text) + Val(a.P2_Q3_Score.Text) + Val(a.P2_Q4_Score.Text)) / 4
 
Upvote 0
Hmm, this still isnt working, i'm getting an "invalid use of property" error now...

Code:
    Dim a As MSForms.Page
    a = UserForm1.MultiPage1("Page2")
    a.P2_ScoreTotal.Value = (Val(a.P2_Q1_Score.Text) + Val(a.P2_Q2_Score.Text) + Val(a.P2_Q3_Score.Text) + Val(a.P2_Q4_Score.Text)) / 4
 
Upvote 0
Got it, this works. Forgot the "Set"

Code:
    Dim a As msforms.Page
    Set a = UserForm1.MultiPage1("Page2")
    a.P2_ScoreTotal.Value = (Val(a.P2_Q1_Score.Text) + Val(a.P2_Q2_Score.Text) + Val(a.P2_Q3_Score.Text) + Val(a.P2_Q4_Score.Text)) / 4

Thanks again for the help!!
 
Upvote 0
Still, I would prefer the With... End With.
But you will use it so you can decide what's best -:)
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top