PDA

View Full Version : Make selection in Drop Down box without opening it



duugg
11-12-2010, 08:00 AM
Hello All,

When I'm on the internet (using Internet Explorer or whatever other browser I wish) filling out a form, I get to the "state" field, and, being the keyboard person I am, I simply type "C C C" for Connecticut.

Once I do that, the selection for Connecticut pops up. Knowing I made my correct selection, I simply hit the TAB key again and move on to the next field.

Well, in Word 2007, it doesn't work the same way. I created several drop-down form fields and, in order for me to make a selection for any form field, I must "open" the form field first, by either...

A) Clicking on the down arrow with the mouse

or

B) Using ALT+Down Arrow on the keyboard


Once the drop box has been opened, I can then make my selection by typing the first letter...once or many times. But then, I must hit enter to close the box before moving onto the next field.

There must be a way, through a simple macro or otherwise that allows me to make a selection from the drop down box without opening it.

I looked briefly into the VBA code help and there seems to be several options that allow for opening and closing drop down form field options, but I don't know the proper syntax to do it.

Here's a couple of pieces of code that I found...


ActiveDocument.FormFields("DropDown1").DropDown.Value = 1
Documents("Sales.doc").FormFields("Colors").DropDown _ .Default = 2 Can anyone help me on this one? Thanks much

fumei
11-12-2010, 10:46 AM
Nope. Sorry, but Word formfields are not the same a web page controls.

Your first code snippet makes the set value of the dropdown = 1.

Your second snippet sets a default, which you can do.

However, you are not asking about code solution in of themselves. You seem to be asking for keyboard functions. If I understand correctly:

1. type Tab (moving into a formfield)
2. type C
3. type C
4. type C
5. type Tab (moving onwards).

This can not be done with formfields. The things you are looking ar onweb pages are closer to ActiveX controls. These CAN act as you wish in Word documents. But be aware that ActiveX controls are quite different from formfields. For one thing, you do not Tab into them. Demo attached.

Click in the control and press "c".

duugg
11-12-2010, 12:26 PM
fumei,

Thanks for the reply. So, there appears to be no code that allows a form field drop down box to be opened upon tabbing to it?

I tried that active x you sent, and it will do what I want, BUT...I tried to copy it and had no luck doing so. How do you do that?

Can Active X controls be placed into specific tables in Word?

I am really stumped as the why, not only can you NOT just use a form in Word the same way that I.E. uses, but also that you can't have it do something simple like use a "click-open" event upon tabbing to it. It just doesn't make sense to me.

How can I create the same Word form I already have and replace every form field drop down box with an active x control instead? Or can this not be done?

Another thought, what if I used Word to create a "web page" that I will never publish and intead, use this "Web page created in Word" so that I can quickly fill out forms and then print them?


Thanks much for all your help...

duugg
11-15-2010, 06:35 AM
Would anyone (including fumei of course) be able to shed some light on this for me?


Thanks

fumei
11-15-2010, 11:05 AM
"So, there appears to be no code that allows a form field drop down box to be opened upon tabbing to it?"

Correct.

"I tried that active x you sent, and it will do what I want, BUT...I tried to copy it and had no luck doing so. How do you do that?"

You have to create them individually.

"I am really stumped as the why, not only can you NOT just use a form in Word the same way that I.E. uses, but also that you can't have it do something simple like use a "click-open" event upon tabbing to it. It just doesn't make sense to me."

The why is simple. Formfields are NOT ActiveX controls; they are NOT the same control objects as controls in IE. They do not have events.

"How can I create the same Word form I already have and replace every form field drop down box with an active x control instead? Or can this not be done?"

By replacing each formfield with an ActiveX control. Be aware that ActiveX controls (unlike formfields) WILL activate Security in Word. For the same reason they work they way they do. They DO have events; they DO execute code.

"Another thought, what if I used Word to create a "web page" that I will never publish and intead, use this "Web page created in Word" so that I can quickly fill out forms and then print them?"

I suppose you could, but IMO this would be a ridiculous amount of work for minimal return. The issue appears to be you want to bypass having to click the down arrow on your formfields.

Go ahead and try it as a web page. I sure as heck would not. Word is bloody awful creating HTML.

duugg
11-17-2010, 11:42 AM
Sorry for the delay and thanks for the reply Gerry.

Okay, I'm playing around with these active X controls.

That small bit of code you gave me is AWESOME!

I think I will be able to work with that code.

2 more questions if I may...


Question 1 - Is there any way for the control to default to the uppermost selection?

So, in this example here...



Option Explicit

Private Sub Document_Open()
Dim yadda() As String
Dim j As Long
yadda = Split("California,Colorado,Connecticut", ",")
For j = 0 To UBound(yadda())
ComboBox1.AddItem yadda(j)
Next
End Sub



Have California show up as the default?




Question 2 - Have Word NOT print the visible drop down box, only the value.

After setting up my first Active X Control in my existing document, I noticed that when printing the document, not only did my selection show up, but a picture of the dropdown box showed in the print version as well. Is there a way to print the value from the dropdown box without the dropdown box also showing up in the print version?


Thanks much :)

fumei
11-17-2010, 01:09 PM
All ActiveX control have a property of ListIndex. It is what is displayed as the current selected item.
Private Sub Document_Open()
Dim yadda() As String
Dim j As Long
ComboBox1.Clear
yadda = Split("California,Colorado,Connecticut", ",")
For j = 0 To UBound(yadda())
ComboBox1.AddItem yadda(j)
Next
ComboBox1.ListIndex = 1
End Sub


The Index is 0-based.

The above would show Colorado.

If you put:

ComboBox1.ListIndex = 0

California would be showing.

Note the use of .Clear. While it is not significant because the populating is being down with Document_Open (therefore the control is empty to start), it is a good habit to use it if you ever want to do any RE-populating while the document is open. Say you have some logic that you want to change the items.

Say another combobox with:

Country
States/Province
Municipalities

And say if you select Country, then a second combobox is populated with:

USA
Canada
Morocco
Spain

but if you select States/Provinces, the same combobox is populated with:

yadda
blah
California

If you do not use a .Clear, any .AddItem istruction is does precisely that. It adds the item. It appends the item, with any existing item remaining. So, if you want to RE-populate a combobox, use .Clear.

However, again, as your code is in Document_Open, this is not important, as Document_open fires only once.

2. Printing. Unfortunately, unlike formfields, there is no native way to print the Value of the controls, and not the controls.

Paul_Hossler
11-17-2010, 03:31 PM
In Word 2007/2010, a Drop Down Content Control will take a typed 'first letter' and position the list to that point.

BUT Content Controls are not the same as form fields

Paul

duugg
11-19-2010, 09:25 AM
Paul thanks for the reply, but I don't think content controls/dropdown form fields will do it.


Gerry thanks again for the help.

Ok, I think I'm much closer. I did manage to get the control to default to the first word, but....my next issues are the following....


Issue 1 - When tabbing to that particular activex control, the box properly defaults to "Colorado".

However, the only way for me to select "Connecticut" is to use the backspace key and delete ALL of Colorado and then, finally, type "C" three times to get to "Connecticut" (using mMatchEntryFirstLetter 0 in the properties of the combo box).

I would like to tab to that box and type "C" three times to select "Connecticut" without having to clear out "Colorado" first




Issue 2 - The box also allows you to put ANY entry into it. I would like to lock the box so that the only values in the combo box are the values defined in the code.



Can this be done?

Thanks much!

duugg
11-20-2010, 10:38 AM
Maybe the "weekenders" can take a shot at this one?