Opening Combo Box Properties

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Opening Combo Box Properties

Post by ABabeNChrist »

I tried recording a macro, with no such luck, is there a piece of code that I could use so that when I click on a select combo box and then press a button that it will open up that selected combo box properties so that new entries may be added. I know this is a real easy task to do without code, but there are some people that are very very limited with computer skills, I was just trying to help and make it as easy as possible

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

What type of combo box is this?

1) A combo box on a userform (created in the Visual Basic Editor)
or
2) A combo box in a document, and if so:
2a) A form field combo box (from Legacy Forms)
2b) An ActiveX combo box
2c) A content control combo box
x169.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

Hi Hans
I'm sorry
It is 2c - a content control combo box

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

I don't know how to display the combo box's properties using code, but you can use code to add an item. The following code operates on the first content control in the document, you can modify it as needed.

Code: Select all

Dim strText As String
strText = InputBox("Enter the text for the new entry")
If Not strText = "" Then
  ActiveDocument.ContentControls(1).DropdownListEntries.Add Text:=strText
End If
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

Thank you Hans
It does work nice at populating, much more user friendly
And by changing the number within the commas I am able to select different combo boxes
Since I have quit a few combo boxes, I’ll play around with this code and see if I can get it to work just by selecting desired combo box then run code

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

You can change

ActiveDocument.ContentControls(1)

to

Selection.ContentControls(1)

to make the code operate on the (first) content control within the selection.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

Hi Hans
It seems that the only way it will work is if I highlight the entire table that combo box content control is located in. If I try to just highlight only the combo box it does not work and I receive an error
error.JPG
and on this line

Code: Select all

 Selection.ContentControls(1).DropdownListEntries.Add Text:=strText
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

I don't think you have to select the entire table, but it's not sufficient to click on the combo box.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

Thank you Hans
I played with it a little and you know, It works just fine the way it is thank you, if it were any easier it would be to telepathically transfer new comments to dropdown, at which I could make millions if I could figure that out

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

Hi Hans
As I work deeper into this document I find more exciting challenges.
Here we go. You earlier assisted me with some code that will help me populated combo box content controls, that works great, now I have some drop down form fields that I wish to do the same.
I tried using the code you provided within this thread, with some slight changes. I can get it to insert a new entry, but it seems to be the same word each time “false”
Here are the changes i made

Code: Select all

    Dim strText As String
    strText = InputBox("Enter the text for the new entry")
    If Not strText = "" Then
        Selection.FormFields(1).Dropdown.ListEntries.Add Text = strText
    End If
    ActiveDocument.Protect wdAllowOnlyFormFields, True, ""

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

Text = strText is an expression that compares the values of Text and strText. It returns True if they are equal, and False if they aren't. Since Text probably hasn't been assigned a value, it is not equal to strText, hence the result is False.

If you had had a line Option Explicit at the top of the module, the Visual Basic Editor would have warned you that Text hasn't been declared. See The importance of 'Option Explicit' for more info about this.

You need to change

Selection.FormFields(1).Dropdown.ListEntries.Add Text = strText

to

Selection.FormFields(1).Dropdown.ListEntries.Add Name:=strText

Note the := instead of = between Name and strText.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

Hi Hans
When I first was trying to do it on my own I tried using Text:= and of course I received an error, and when I removed : the error was gone. But then of course I received a false statement. I have now added "Option Explicit"
Is it possible to combine both methods “combo box content controls” and “drop down form fields” in a way that whichever one happens to be selected it would then enter new comment?

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

Why would you want to use both in one document? I'd use either one or the other.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

With drop down form fields I am able to run code during entry and exit, but can only be populated to 25 entries
where as a combo box content control will give me many more entries if needed

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

By the way, the Visual Basic Editor displays popup help for the Add method of the ListEntries object:
x175.png
From this, you can see that the argument you need is Name, not Text.

You can also look up ListEntries.Add in the built-in or online help: see Add Method [Word 2007 Developer Reference]; it comes with an example showing how to use it.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

ABabeNChrist wrote:With drop down form fields I am able to run code during entry and exit, but can only be populated to 25 entries
where as a combo box content control will give me many more entries if needed
Dropdown lists with a large number of items are difficult to use; I think 25 items is a very sensible limit.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

I'm learning something new everyday
Very cool Thank you Hans

I do understand what you mean by 25 items are a very sensible limit.
This report will be used out in the field by home inspectors, and with so many possible scenarios, the more choices can be a plus, within in reason of course. I try to leave the door open so that if 26 comments are needed it is then possible.

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

In such a situation, I'd provide two dropdowns: the user selects a category from the first one, then an item within the selected category from the second one.

See my reply in post #4 in the thread synchronised combos (2000); it comes with a downloadable sample document.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening Combo Box Properties

Post by ABabeNChrist »

I checked it out and I like it but found it difficult for unskilled user to populate if needed.

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening Combo Box Properties

Post by HansV »

Another option would be to add "Other, please specify" to the dropdown as the last item, and to omit the option for the end user to add items. Instead, provide a form text box next to the dropdown in which the user can specify the "Other" option.
Best wishes,
Hans