How to Make Tabbing work from VBA

G

Gary Hillerson

I'm trying to figure out how to get tabbing from field-to-field to work in
userForms I'm creating with VBA in Word 2004 on the Mac. Right now, the only
way to change focus is to click the mouse in another textbox, even tho the
tab key properly generates an Exit event.

As a simple test, I create a simple form with four controls: TextBox1,
TextBox2, TextBox3, and a Cancel button that unloads the form.

I implement the _Enter and _Exit methods of each textbox to display a debug
message, e.g. "TextBox2_Enter"

I type something into TextBox1 and then press the Tab key.

I get an Exit event on TextBox1, and an Enter event on Textbox2, as
expected.

But then, I immediately see TextBox2_Exit, TextBox3_Enter, TextBox3_Exit,
and TextBox1_Enter. The net result is that the same control (TextBox1) ends
up with the focus.

Even manually calling the SetFocus method of one textbox from another's Exit
method doesn't work; the focus always cycles back to the textbox in which I
press the Tab key.

There must be some way to work around this tabbing problem, but I'm not
finding it. Can anyone help?

thanks

Gary
 
J

John McGhie [MVP - Word and Word Macintosh]

Gary:

No. We have never made it work. It's buggy, and they're not going to fix
it (because VBA is deprecated).

Microsoft has made the decision to retire VBA because by design it cannot be
adequately secured. Consequently, they are not going to put any further
development effort into it.

On the PC, use VBA.NET (or C sharp...). VBA.NET is actually a different
language that just happens to have similar syntax.

On the Mac, use AppleScript. Microsoft is putting all the available
(limited) resources into fixing and enhancing AppleScript as its Mac Office
scripting language. Alternatively, re-express your design in RealBasic,
which ships as an optional install for Mac Office.

Cheers


I'm trying to figure out how to get tabbing from field-to-field to work in
userForms I'm creating with VBA in Word 2004 on the Mac. Right now, the only
way to change focus is to click the mouse in another textbox, even tho the
tab key properly generates an Exit event.

As a simple test, I create a simple form with four controls: TextBox1,
TextBox2, TextBox3, and a Cancel button that unloads the form.

I implement the _Enter and _Exit methods of each textbox to display a debug
message, e.g. "TextBox2_Enter"

I type something into TextBox1 and then press the Tab key.

I get an Exit event on TextBox1, and an Enter event on Textbox2, as
expected.

But then, I immediately see TextBox2_Exit, TextBox3_Enter, TextBox3_Exit,
and TextBox1_Enter. The net result is that the same control (TextBox1) ends
up with the focus.

Even manually calling the SetFocus method of one textbox from another's Exit
method doesn't work; the focus always cycles back to the textbox in which I
press the Tab key.

There must be some way to work around this tabbing problem, but I'm not
finding it. Can anyone help?

thanks

Gary

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
G

Gary Hillerson

John,

Thanks. I understand what you're saying, but I've got a giant piece of
VBA code that isn't going to get rewritten in a hurry, especially with
limited resources. And the code works in Office 2004, aside from a few
very minor issues. The worst is this tabbing problem.

I understand that the built-in tabbing won't work properly, but I have
to believe that I can "manually" make it work by catching the right
event and handling it in some way. And it sure seems like someone must
have figured out the correct sequence of events along the way.

If not, we'll just have to tell users to click instead of tabbing.

Thanks again,
gary
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Gary:

I understand that the built-in tabbing won't work properly, but I have
to believe that I can "manually" make it work by catching the right
event and handling it in some way. And it sure seems like someone must
have figured out the correct sequence of events along the way.

If not, we'll just have to tell users to click instead of tabbing.

Yep. You will :) As far as I know, the reason it can't be made to work is
that it's unstable. So whatever works today won't work the next time you
open the solution.

I also told you something else. If you re-read what I said you may pick it
up. If not, email me direct off-line.

Cheers

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
J

Jeffrey Frankel

Bummer. I just ran into the same problem Gary did. Several years ago I dove
into VBA for Word for Macintosh 2001 or v.X (I forget which), wrote an
application with a user form, and then, with a little bit of help,
transferred it into Word 2000 for use at work. Recently, I dusted off the
Mac version to demonstrate for my user group. Lo and behold, tabbing in the
user form no longer works in the Mac version, and I was going nuts trying to
figure out why until I found this thread.

Like Gary notes, tabbing works fine on the Windows side, now running Word
2003. The funny thing, unless my memory is way off, is that to the best of
my recollection tabbing *used* to work in Word for Macintosh as well. Not
that it matters any more, but am I mistaken on this point?

Jeff Frankel
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Jeffrey:

No, I think you're correct. As far as I recall, tab order worked in VBA up
to Word 2001, and gotten broken in Word X. It may have been Word 2004.

The problem is: Now it's broken, and there's no budget to fix it. :)

cheers


Bummer. I just ran into the same problem Gary did. Several years ago I dove
into VBA for Word for Macintosh 2001 or v.X (I forget which), wrote an
application with a user form, and then, with a little bit of help,
transferred it into Word 2000 for use at work. Recently, I dusted off the
Mac version to demonstrate for my user group. Lo and behold, tabbing in the
user form no longer works in the Mac version, and I was going nuts trying to
figure out why until I found this thread.

Like Gary notes, tabbing works fine on the Windows side, now running Word
2003. The funny thing, unless my memory is way off, is that to the best of
my recollection tabbing *used* to work in Word for Macintosh as well. Not
that it matters any more, but am I mistaken on this point?

Jeff Frankel

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 

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