PDA

View Full Version : Solved: How to set the default value of activedocument.formfields().dropdown



abvnewbie
07-15-2008, 11:49 AM
Alright, this one's been bogging me down and I'm sure it's simple but can't figure out a good work around.

Is there a way to set the default value for a Word formfields dropdown using VBA? It's simple enough to do so manually when you edit the dropdown attributes but the problem is that this dropdown is populated based on other user selections (simplified version below). So the question is, after populating the dropdown is there a way to make a certain value the default that will show up on the activedocument form without user selection? The default and value seem to be read-only attributes (can this be changed somehow?).


Set oDD = ActiveDocument.FormFields("changecause").DropDown

With oDD.ListEntries
.Add "Option A"
.Add "Option B"
.Add "Option C"
.Add "OTHER "
End With

I realize the simplest way to write the selection to the form is to use a text form field but I'd like to maintain the dropdown within the form in case the user wants to manually change the selection without having to go through the whole process of having the dropdown repopulated.

macropod
07-17-2008, 04:58 PM
Hi abvnewbie,

Try:
oDD.Default = #
where # is the required default entry number from your dropdown list.

abvnewbie
07-21-2008, 12:23 PM
No can do.

Activedocument.FormFields("changecause").Dropdown.Default = "whatever"

results in a type mismatch, presumably because in a formfield dropdown the "default" is a read-only attribute. I have come to accept this as a matter of fact and changed the dropdown on the form to an activeX combobox which works just fine because the "value" attribute is not read-only:

ActiveDocument.ComboBoxCause.Value = "whatever"

macropod
07-21-2008, 02:40 PM
Hi abvnewbie,

No can do.

Activedocument.FormFields("changecause").Dropdown.Default = "whatever"

results in a type mismatch, presumably because in a formfield dropdown the "default" is a read-only attribute.No, 'Default' is not a read-only attribute. From Word's Help file:
Default Property
DropDown object: Returns or sets the default drop-down item. The first item in a drop-down form field is 1, the second item is 2, and so on. Read/write Long.

Your problem is because you're trying to set the default property as a text string, whereas it's an index number pointing to whichever of the dropdown entries you want to use as the default - as indicated in my previous post and the Word help.

abvnewbie
07-22-2008, 11:56 AM
Wow, never figured that was an index/integer value. How stupid do I feel! Thanks for straightening me out on this.:thumb