Setting focus to combobox on page 2 of multipage control when tabbingfrom last textbox on page 1

P

Patrickw

When I tab or exit from the last textbox control on page 1 of a
multipage (tabbed) container, I would like to switch to page 2 of the
multipage container and set the focus to the first combobox on page
2. I tried the following, with wierd results:

Private Sub TXTPara12_AfterUpdate()

MLTResponse.Value = 1
CBOPara13.SetFocus

End Sub

I have also tried the code in the Exit event, setting cancel to false.
 
G

Gordon Bentley-Mix

Patrick,

Sorry to be the bearer of bad news, but in my extensive experience with
MultiPage controls, I have never found a way to set focus to a control on
another page and, most especially, to cause a different page to be displayed
through code. It just doesn't seem to work, and I don't hold much hope for
success in your endeavour.
 
G

Greg Maxey

Oh ye of little faith ;-)

Create a simple multipage form (page 0 and page 1). Add two textboxes to
page 0 and two text boxes and a combobox on page 1. Name the combobox
cbFirst.

Logically the following should work but it doesn't. When you tab from the
second textbox on page 0 theExit event "does not" fire and the focus shifts
to the page tab. You have to mouse off the tab for the Exit event to fire
:-(

Option Explicit

Private Sub UserForm_Initialize()
Me.MultiPage1.Value = 0
End Sub

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.MultiPage1.Value = 1
Me.cbFirst.SetFocus
End Sub

However, with some added trickery you can force it to work. Add another
textbox textTiny to the page 0 control. Size it 1 point x 1 point with flat
effect (it has to be set to visible but you won't see it). Now run the same
code.

With the added control the Exit event fires as expected and the focus jumps
to the cbFirst on page 1.

Is this what you are looking for?

Patrick,

Sorry to be the bearer of bad news, but in my extensive experience
with MultiPage controls, I have never found a way to set focus to a
control on another page and, most especially, to cause a different
page to be displayed through code. It just doesn't seem to work, and
I don't hold much hope for success in your endeavour.

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the
strong man stumbles, or where the doer of deeds could have done them
better. The credit belongs to the man in the arena, whose face is
marred by dust and sweat and blood, who strives valiantly...who knows
the great enthusiasms, the great devotions, who spends himself in a
worthy cause, who at the best knows in the end the triumph of high
achievement, and who at the worst, if he fails, at least fails while
daring greatly, so that his place shall never be with those cold and
timid souls who have never known neither victory nor defeat." - TR
 
P

Patrickw

Wierd, but it worked perfectly.

How do you guys figure stuff like that out, anyway?

Thanks.
 
G

Greg Maxey

Never ever give up ;-)

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR
 
G

Gordon Bentley-Mix

Well slap me with a wet bus ticket and call me Lucy! It's a hack but it
definitely works.

Now I'm going to try to work out the following:

In the Click event of a CommandButton (e.g. the 'OK' button) I run code to
validate the values in various TextBoxes located on different Pages across
the UserForm. If the validation fails, I've never been able to get the Page
containing the offending TextBox to show automatically with the focus set
appropriately. However, I think the answer to the problem might lie in
setting the .Value property of the MultiPage control as shown in Greg's
code.

My faith has been restored. Hallelujah!
 
G

Gordon Bentley-Mix

Lo and behold! I have seen the light! My validation checks now fail
gracefully.

Thanks Greg. You have no idea of the number of hoops you've removed from the
obstacle course of my code. Now it's just a matter of doing a heap of
remedial action to eradicate said hoops from my legacy code. ~sigh~
 
G

Greg Maxey

Faith has made you whole ;-).

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR
 
B

bigrho1

I use the following in a Multipage control because I don't know how many
pages I will have.

MultiPage1.Value = MultiPage1.Value + 1
It will automatically set the focus on the first control (based on tab
order) on the next page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top