Open Multipage Userform at specific page

inarbeth

Well-known Member
Joined
Apr 8, 2002
Messages
912
I have a multipage userform (currently only two pages but I intend to add more). The form is opened from different worksheets using different Command Buttons. I want to be able to open the form at Page 0 if one Command Button is clicked and at Page 1 if a second Command Button is clicked. I have tried putting MultiPage1 = 0 or = 1 in the code for the relevant button but the form always opens on Page 1. Is there a way to do this? I tried adapting the code from http://www.ozgrid.com/forum/showthread.php?t=23932
but the line
Code:
Public strMacro As String
causes a problem
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What problem does that line cause? It needs to be in a General module so that the variable is visible to all procedures.
 
Upvote 0
A compile error that a variable is not defined.
My code is:
Code:
Public strMacro As String
Private Sub Userform_Initialize()
   Select Case strMacro
    Case "CompletionStatement"
        MultiPage1.Value = 0
    Case "GrantofLease"
        MultiPage1.Value = 1
    End Select
frmCompStatement.Show 
End Sub
and
Code:
Private Sub CMDLeaseForm_Click()
   
       strMacro = "GrantofLease"
frmCompStatement.Show

End Sub
for one button and
Code:
 Sub cmdFillForm_Click()
    strMacro = "CompletionStatement"
    frmCompStatement.Show
End Sub
for the other button.
 
Upvote 0
The problem is you are referring to a variable that's been declared in the userform module.

Try this.
Code:
Private Sub CMDLeaseForm_Click()
    frmCompStatement.MultiPage1.Value = 1
    frmCompStatement.Show
End Sub
Sub cmdFillForm_Click()
    frmCompStatement.MultiPage1.Value = 0
    frmCompStatement.Show
End Sub
 
Upvote 0
The problem is you are referring to a variable that's been declared in the userform module.

Try this.
Code:
Private Sub CMDLeaseForm_Click()
    frmCompStatement.MultiPage1.Value = 1
    frmCompStatement.Show
End Sub
Sub cmdFillForm_Click()
    frmCompStatement.MultiPage1.Value = 0
    frmCompStatement.Show
End Sub

Norie, thank you - that does the job perfectly. Andrew, thank you also. I will experiment with that.
 
Upvote 0

Forum statistics

Threads
1,206,971
Messages
6,075,922
Members
446,170
Latest member
zzzz02

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