Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macro: Remapping Enter action to "Tab"? 1

Status
Not open for further replies.

AndrewJC

MIS
Sep 26, 2003
13
US
I'm working on creating a form in Word. We're trying to see if there's a way we can use Enter to navigate through the form, and although Microsoft has a way to do that in its Knowledge Base, it's not quite what we need, for this reason:

When you use the Microsoft script to navigate through a form using Enter, it causes the form to ignore any updates that the form fields have to make (i.e. if you have a text field set to capitalize everything, or if you have a specific date format in a date text field, they don't capitalize/change date format when you hit Enter).

My idea was that I simply use an AutoOpen macro to remap the Enter action as the Tab action, which will take care of that. Unfortunately, it seems that there is no easy way to simply use KeyBindings to map one key's function to mirror that of another key, only to run a function/macro/autotext entry.

Does anybody have any ideas on how I can do this?
 
Not sure if this is what you need.

In word 2003, there is a property EnterKeyBehavior that is set to false by default, and that says "Pressing ENTER moves the focus to the next object in the tab order (default)."

So by setting the tab order on the desired objects you may be able to accomplish what you need. Not sure if it was available on Word 2000 or Word XP

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
I'm using Word 2003, and I can't seem to find this property. Where might I find it and/or set it?

Plus, even though I might be able to fix this particular issue with a different method (as with the initial reponse), I'd still like to know if it's possible to simply remap one key to use another's functionality. It'd be a heckuvalot easier than creating a custom keyboard layout, and you'd also be able to do it document-by-document.
 
Ah, now I see what you're talking about. However, I don't see an "EnterKeyBehavior" property in the properties for the text box...

Ah, wait. Yes, I do, but I think I've been misunderstood. You seem to be talking about a text field in a UserForm, whereas I'm talking about formfields in the document itself.
 
Hi Andrew,

This can be done but it isn't very nice.

Create a macro
Code:
[blue]Sub MyFormFieldTab()
    SendKeys "{PGDN}"
End Sub[/blue]

and bind the Enter Key to it.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,

Thank you, that was EXACTLY what I was looking for. Since this form is protected and is only meant to be filled out electronically, we don't have to worry about the Enter key action (in fact, we don't WANT the Enter key to do its default function, as this messes with the layout of the form).

Thanks so much for your help! Now if only I can figure out how to get arrow keys to select the next/previous entries in a drop-down field, I'll be golden. :)
 
UH, I don't know if this helps, but F4 opens the drop down list of the current dropdown formfield, and then the arrow keys do in fact select entries.

Gerry
See my Paintings and Sculpture
 
Yes, I've seen that too—Alt-up/down arrowkey also brings up the list, but it's really not what we're looking for. The idea behind a form like this is speed, and when somebody who doesn't know that you can hit F4 goes to fill out the form, they're going to want to use either the arrowkeys or the mouse.

I think what I'm going to have to do is something like the following:

- Check to see that the selected object is a drop-down field
- If the arrowkey is pressed, change the field to the next item in the list, unless it's the last item in the list, in which case switch to the first item
- If it's not in a drop-down field, act as a standard arrowkey action (i.e. move to the next form field)

Not quite sure how I can check to see if the selected object is a drop-down field, though... I'm working on that one. It sounds pretty simple, in theory, but I don't know VBA well enough to do it offhandedly.
 
Gerry: I was about to write something about that only selecting the first object in the document, but the Selection.Formfield(1) means that it's the first object in the selection, doesn't it? That should work great. Thanks!

Frederico: Truth be told, I suppose it's mainly because I have absolutely no experience with VBA forms, and also because this is a form that's used for printing rather than data gathering, which I would guess a VBA form would be better for. But mainly it's because I wouldn't even know where to start with it, and this will accomplish what I'm looking for anyway.
 
Careful, Word can get kinda weird with Selection.FormFields(1) if it is a textbox.

Please post back when you get it working the way you want.

I am not sure exactly what is happening witgh your form. I see you are remapping. OK, but what are you doing with the drop downs?

Are you eventually trying to cycle through the formfields? Are you making a Selection that will cover multiple formfields? if so, why?

Say your selection DOES cover multiple formfields, then you could:

Dim mFF As FormField
With Each mFF in Selection.FormFields()
If mFF.Type = 83 ' this is the numeric for DropDowns
blah blah

Anyway, good luck, and post back if it works well for you.

Gerry
See my Paintings and Sculpture
 
Yeah, I've noticed that Word is acting funky with the Selection.FormFields(1) action and text boxes. I may have to retool this...

So here's the description of what I'm using the form for. Technically, it's not a form, it's a template. It's a predefined template page which contains certain fields which can be filled in. Among these are server name, department, dates, etc.

Several of the fields are text fields, and a few of them are drop-downs, such as the department field, for example. Ultimately, we want to be able to navigate through the form without having to use the mouse at all, which is possible, but not easy to do. Especially for those of us who aren't as technically adept with Word, it becomes difficult to do speedily. Making it so that you can tab into the drop-down field and simply use the arrow keys to cycle through its entries would speed things up. Mostly, though, it's just an academic exercise for me to figure out how to do these things.

But it wasn't until after I did figure out how to get the macro to do what I wanted that I realized that you can't rebind the arrow keys. Oh well.
 
Hi Andrew,

I can remap the arrow keys in Word 2003. What problem are you having?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Let's see if I got it correctly.

When your users select this template the only thing you allow them to change is the values on the formfields you have defined. They can't enter any other type of information into the document, neither can they change it's format and do other things to the document

Is the above correct?

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Tony: Hmm. I was trying to use the following entry:
Code:
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), KeyCategory:=wdKeyCategoryMacro, Command:="EnterKeyMacro"
for an arrow key... But there doesn't appear to be a wdKeyDown or anything like that.

Frederico: Yes, that's exactly right. The form is merely for entering information, and no changes to the layout or its format in any way.
 
Hi Andrew,

I had to record myself doing this to get the values - there don't appear to be any Word constants but the values are:

BuildKeyCode(37) = Left
BuildKeyCode(38) = Up
BuildKeyCode(39) = Right
BuildKeyCode(40) = Down


Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Awesome. So I guess now the question is what can I use instead of Selection.FormFields(1), since I'm using text fields? Also, since I want the down key to have normal usage when I DON'T have a drop-down selected, what would be the best method to use? I figured that I could use Selection.MoveDown when protection isn't enabled (say, when I'm editing the template), but something tells me that that won't be so helpful if I'm in, say, a text field. It's not the end of the world if I have to make it do nothing when there's a text field selected, but I'm one of those really anal-retentive guys who likes to cover ALL bases.

Yes, anal-retentive is hyphenated. ;)
 
Hi Andrew,

Would it be too awkward for you to run something in an Entry macro on each Dropdown to map the keys and in an Exit macro to unmap them? Either have your routines set as such a macro or have them called from any other ones you already have. Doing that would obviate the need for checking Selection.FormFields(1) - or am I missing something?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top