PDA

View Full Version : Solved: SetFocus on Control In MultiPage



CreganTur
06-16-2008, 12:10 PM
Background: I'm automating a group of letters that are currently all manual entry, by providing a UserForm with textboxes, so that the users can fill out all the info, click generate, and have their info populate to the letter. All of this works perfectly.

Currently I'm working on data validation, which includes ensuring that required textboxes are not empty. I've got it so that a MsgBox will fire and focus will be set to the offending textbox. However, the letter I'm working on right now has so many fields required that I'm using a MultiPage to keep the UserForm small.

This multipage only has 2 tabs (pgAccount & pgFinancial). pgAccount is the page that has focus by default. If the user forgets a textbox on pgFinancial while pgAccount has focus, then I get an error because that textbox is hidden behind the page.

How can I set my code so that the correct page will get focus, so that the textbox can then get focus?

CreganTur
06-16-2008, 12:31 PM
:doh: I figured it out.

I have to set the value of the multipage to be the page# I want to look at. Since VBA starts numbering at Zero (unless otherwise declared) this means that the value of page 2 is "value = 1"

So using this just before the set focus for my textbox fixed the issue:
Me.MultiPageName.Value = 0 '<<<for page 1 | use value = 1 for page 2
Me.TextBoxName.SetFocus

MOS MASTER
06-16-2008, 02:45 PM
People solving there own questions... aint life grant!

That's the way to go! :)

lucas
06-17-2008, 09:42 AM
Randy is becoming a regular contributor......he just stumbled across one of the oddities of indexes and should bear in mind that this holds true in array's as well.

CreganTur
06-17-2008, 09:47 AM
he just stumbled across one of the oddities of indexes and should bear in mind that this holds true in array's as well.

How so? Can you go into a little more detail on the array piece?

lucas
06-17-2008, 10:04 AM
Hi Randy,
Put this in a standard module in Word or Excel and run it. The message box will return Mon

Sub a()
Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
MyDay = MyWeek(0)
MsgBox MyDay
End Sub


If you change it to:

MyDay = MyWeek(1)

it will return Tue

fumei
06-17-2008, 10:14 AM
Unless set otherwise, arrays are zero-based.

I would also like to thank Randy for posting his own solution.

Also, if I read the timestamps correctly, you figured it out in 20 minutes. That is excellent. Man, it took me MUCH longer to get the hang of multi-pages. Good for you.

And good for you for using multipages in order to keep the userform itself a reasonable size. I wish more people would use them.

CreganTur
06-17-2008, 11:13 AM
Unless set otherwise, arrays are zero-based.

Thanks Lucas and Gerry, after a little research I found that Option Base 1 is the required command for starting array (and multipage) counting at 1 instead of 0.



Also, if I read the timestamps correctly, you figured it out in 20 minutes. That is excellent. Man, it took me MUCH longer to get the hang of multi-pages. Good for you.

Heh... thanks. All it took was a liberal use of Google :whistle:
And thanks for all of the postive feedback. I know you've gotten some flack about that in the past and just wanted make sure I said that. :thumb


And good for you for using multipages in order to keep the userform itself a reasonable size. I wish more people would use them.
It does make the design more pleasing to the eye (was going to say aesthetically pleasing... but wasn't sure if it was speelled corek'ly) And it allows me to "control" the user a little more.

I just had a hard time figuring out the difference between multipage and tabstrip... not sure I understand the difference yet either.

fumei
06-17-2008, 12:56 PM
"figuring out the difference between multipage and tabstrip"

yeah....me too.