Userform multipage problem - simple solution?

tcy999

Board Regular
Joined
Oct 4, 2004
Messages
74
Hi.
I've created a userform in Excel, and everything works fine except this..
I've used the following code to make sure that when the macro button for submitting data entered is pressed, data is not submitted without one of the cells (part number) being entered...

'check for a part number
If Trim(Me.txtQty.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If

However, I've used the multipage tool to make the userform two pages. This button is at the bottom of page 2, but the data it refers to is on the top of page 1, and now the button won't work (I get an error message telling me to debug). Any ideas please?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
It's been a while since I've coded a UserForm with a page control. But if memory serves, you'll need to change the value of the multipage control before you can SetFocus to a control on a certain page. Think it would look something like:

Code:
Me.MultiPage1 = 0
Me.txtPart.SetFocus

I think the page enumeration is zero-based, but you might double check. Also, if that syntax isn't working you might have to use a longer syntax like:

Me.MultiPage1.Pages(0).txtPart

to reach your control.

HTH
 
Upvote 0
Hi Greg, thanks for your response. I tried this, but now I am getting an error message which says "Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept th focus." I'm confused as the control works fine if placed on the same page as the parts number..
 
Upvote 0
The following works fine for me. Note that I did have to explicitely tell Excel to set the value of multipage1 to 0 -- got an error otherwise.

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
    <SPAN style="color:#00007F">If</SPAN> Me.TextBox1.Value = "" <SPAN style="color:#00007F">Then</SPAN>
        MsgBox "Blank"
        Me.MultiPage1.Value = 0
        Me.TextBox1.SetFocus
    <SPAN style="color:#00007F">Else</SPAN>
        MsgBox Me.TextBox1.Value
        Me.Hide
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,619
Members
449,039
Latest member
Mbone Mathonsi

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