Rebuild select list for combo/list box 
Author Message
 Rebuild select list for combo/list box

I can't figure out how to dynamically rebuild the select
list for combo boxes and drop-down lists.  Can anybody
point me in the right direction.

TIA

Joe Gabay



Mon, 12 Sep 2005 04:53:40 GMT  
 Rebuild select list for combo/list box
Joe

I'm assuming by ComboBox you're refering to an ActiveX control and that by
Dropdown your refering to a Dropdown Form Field.

To reset a Dropdown FormField named "Dropdown1":

    Dim ffDropDown As Word.FormField
    Set ffDropDown = ActiveDocument.FormFields("Dropdown1")
    With ffDropDown.DropDown.ListEntries
        .Clear
        .Add "Red"
        .Add "Green"
        .Add "Blue"
    End With

To reset a ActiveX ComboBox control called "cboTest":

    With cboTest
        .Clear
        .AddItem "Red"
        .AddItem "Green"
        .AddItem "Blue"
    End With

Both examples clear any existing items, then add three new ones: Red, Green
and Blue.

I hope this helps + Cheers - Peter



Quote:
> I can't figure out how to dynamically rebuild the select
> list for combo boxes and drop-down lists.  Can anybody
> point me in the right direction.

> TIA

> Joe Gabay



Mon, 12 Sep 2005 08:04:14 GMT  
 Rebuild select list for combo/list box
Peter;

Thank you very much for your assistance, it turned out to
be quite helpful.  If I may impose upon you once more, I
am trying to load this items with a second programs which
opens the original document and then follows down the
inlineshapes list.

i.e.
  With objWordDoc
    For i = 1 To .InlineShapes.Count
      Debug.Print .InlineShapes.Item(i)
      .OLEFormat.ClassType
      Debug.Print .InlineShapes.Item(i)
      .OLEFormat.object.Name,
      Debug.Print .InlineShapes.Item(i)
      .OLEFormat.object.Value
    Next
  End With

When I get to the item I am looking for, in this case
combo boxes, how do I clear and reload their select lists?

You really don't have to send me code samples, just point
me in the right direction.

TIA

Joe Gabay

Quote:
>-----Original Message-----
>Joe

>I'm assuming by ComboBox you're refering to an ActiveX

control and that by
Quote:
>Dropdown your refering to a Dropdown Form Field.

>To reset a Dropdown FormField named "Dropdown1":

>    Dim ffDropDown As Word.FormField
>    Set ffDropDown = ActiveDocument.FormFields
("Dropdown1")
>    With ffDropDown.DropDown.ListEntries
>        .Clear
>        .Add "Red"
>        .Add "Green"
>        .Add "Blue"
>    End With

>To reset a ActiveX ComboBox control called "cboTest":

>    With cboTest
>        .Clear
>        .AddItem "Red"
>        .AddItem "Green"
>        .AddItem "Blue"
>    End With

>Both examples clear any existing items, then add three

new ones: Red, Green
Quote:
>and Blue.

>I hope this helps + Cheers - Peter




- Show quoted text -

Quote:

>> I can't figure out how to dynamically rebuild the
select
>> list for combo boxes and drop-down lists.  Can anybody
>> point me in the right direction.

>> TIA

>> Joe Gabay

>.



Tue, 13 Sep 2005 01:06:55 GMT  
 Rebuild select list for combo/list box
Hi Joe

Why don't you do this from within the applications that create and maintain
these documents. What "documents" (Excel, etc.) are you embedding/linking in
you Word document?

If you're embedding shapes created with other applications your going to have
to do some very complex stuff! You'll need to determine each shapes
application and use that application programatically to manage the objects.

Good luck + Cheers - Peter



Quote:
> Peter;

> Thank you very much for your assistance, it turned out to
> be quite helpful.  If I may impose upon you once more, I
> am trying to load this items with a second programs which
> opens the original document and then follows down the
> inlineshapes list.

> i.e.
>   With objWordDoc
>     For i = 1 To .InlineShapes.Count
>       Debug.Print .InlineShapes.Item(i)
>       .OLEFormat.ClassType
>       Debug.Print .InlineShapes.Item(i)
>       .OLEFormat.object.Name,
>       Debug.Print .InlineShapes.Item(i)
>       .OLEFormat.object.Value
>     Next
>   End With

> When I get to the item I am looking for, in this case
> combo boxes, how do I clear and reload their select lists?

> You really don't have to send me code samples, just point
> me in the right direction.

> TIA

> Joe Gabay

>>-----Original Message-----
>>Joe

>>I'm assuming by ComboBox you're refering to an ActiveX
> control and that by
>>Dropdown your refering to a Dropdown Form Field.

>>To reset a Dropdown FormField named "Dropdown1":

>>    Dim ffDropDown As Word.FormField
>>    Set ffDropDown = ActiveDocument.FormFields
> ("Dropdown1")
>>    With ffDropDown.DropDown.ListEntries
>>        .Clear
>>        .Add "Red"
>>        .Add "Green"
>>        .Add "Blue"
>>    End With

>>To reset a ActiveX ComboBox control called "cboTest":

>>    With cboTest
>>        .Clear
>>        .AddItem "Red"
>>        .AddItem "Green"
>>        .AddItem "Blue"
>>    End With

>>Both examples clear any existing items, then add three
> new ones: Red, Green
>>and Blue.

>>I hope this helps + Cheers - Peter




>>> I can't figure out how to dynamically rebuild the
> select
>>> list for combo boxes and drop-down lists.  Can anybody
>>> point me in the right direction.

>>> TIA

>>> Joe Gabay

>>.



Tue, 13 Sep 2005 05:38:14 GMT  
 Rebuild select list for combo/list box
Peter;

I want to build/rebuild several combobox/drop-down lists
from an Access database.  They are included in a rather
complex word document and I do not want to expose either
my source code for building the lists or my database to
the end user.  This would also have the advantage of
making the document itself rather dynamic, and any changes
in the database structure would only have to be reflected
in the program that builds the document.  Am I making any
sense or am I trying to do the impossible?

Joe



Sat, 17 Sep 2005 01:08:28 GMT  
 Rebuild select list for combo/list box
Hi Joe

If you can do what you want directly from Word VBA then you can do it using
COM. The code I provided if prefixed with a Word Application instance
variable will work just as well from Access using COM. Just make sure you
create a Reference to Word from the Access IDE, Tools/References. Here's the
first option modified for COM:

    Dim wdApp as Word.Application
    Dim docNew as Word.Document
    Dim ffDropDown As Word.FormField

    ' Create an instance of Word
    Set wdApp = New Word.Application

    ' Create a new Word document based on the template Test.dor
    Set docNew = wdApp.Documents.Add "c:\my template\test.dot"

    ' Populate the documents dropdown control
    Set ffDropDown = docNew.FormFields("Dropdown1")
    With ffDropDown.DropDown.ListEntries
        .Clear
        .Add "Red"
        .Add "Green"
        .Add "Blue"
    End With

    ' Dispose of Word
    wdApp.Quit
    Set wdApp = Nothing

I hope this is what you were looking for.

Cheers - Peter



Quote:
> Peter;

> I want to build/rebuild several combobox/drop-down lists
> from an Access database.  They are included in a rather
> complex word document and I do not want to expose either
> my source code for building the lists or my database to
> the end user.  This would also have the advantage of
> making the document itself rather dynamic, and any changes
> in the database structure would only have to be reflected
> in the program that builds the document.  Am I making any
> sense or am I trying to do the impossible?

> Joe



Sat, 17 Sep 2005 04:09:56 GMT  
 Rebuild select list for combo/list box

Peter;

Thanks again.  However, since I built the prototype
document by hand, the combo boxes I'm concerned with show
up in the Watch Window as InlineShapes and their ClassType
is "Forms.ComboBox.1".  What I can't figure out is how to
open these things up so that I can build their select
lists.  Any help would be appreciated.

TIA

Joe Gabay



Sun, 18 Sep 2005 00:21:44 GMT  
 Rebuild select list for combo/list box
Hi Joe

What you're trying to do does not make sense! The problem is that the ActiveX
ComboBox control does not have persistent values (no ActiveX controls do)!
When an ActiveX control is placed on a UserForm (a form built in the VBA IDE)
the control is normally initialised in the Forms UserForm_Initialize event.
When an ActiveX control is placed on a document the control is normally
initialised in the documents Document_New or Document_Open event.

But wait - it gets even worse :(. Although it's possible to active and work
with the embedded document none of it's event handlers are going to work
(these are the procedures that respond to ComboBox selection, CheckBox clicks
etc.) because there is already code running - your code that just activated
the embedded document. You could possibly kludge around it by activating the
embedded document and then having your code run the documents Document_New or
Document_Open procedure to initialise the documents controls. You would then
have to terminate your macro so the embedded documents event handling
procedures would work. At this stage the user is manually ineracting with the
document. You've then got the problem of how do you get programatic control
back. Essentially this can't happen unless the users somehow starts more of
your code.

Only the FormField Dropdown field has persistent values, but is limited to a
maximum of 20 values.

I hope the above is helpful even if it's not what you wanted to hear!

Cheers - Peter



Quote:
> Peter;

> Thank you very much for your assistance, it turned out to
> be quite helpful.  If I may impose upon you once more, I
> am trying to load this items with a second programs which
> opens the original document and then follows down the
> inlineshapes list.

> i.e.
>   With objWordDoc
>     For i = 1 To .InlineShapes.Count
>       Debug.Print .InlineShapes.Item(i)
>       .OLEFormat.ClassType
>       Debug.Print .InlineShapes.Item(i)
>       .OLEFormat.object.Name,
>       Debug.Print .InlineShapes.Item(i)
>       .OLEFormat.object.Value
>     Next
>   End With

> When I get to the item I am looking for, in this case
> combo boxes, how do I clear and reload their select lists?

> You really don't have to send me code samples, just point
> me in the right direction.

> TIA

> Joe Gabay



Sun, 18 Sep 2005 03:24:26 GMT  
 Rebuild select list for combo/list box
Peter;

Thank you for your help and patience.  I sort of thought
that I was entering the realm of the impossible when I
started this project.  I'll just have to figure another
way.

Thanks again,

Joe Gabay

Quote:
>-----Original Message-----
>Hi Joe

>What you're trying to do does not make sense! The problem

is that the ActiveX
Quote:
>ComboBox control does not have persistent values (no

ActiveX controls do)!
Quote:
>When an ActiveX control is placed on a UserForm (a form

built in the VBA IDE)
Quote:
>the control is normally initialised in the Forms

UserForm_Initialize event.
Quote:
>When an ActiveX control is placed on a document the

control is normally
Quote:
>initialised in the documents Document_New or

Document_Open event.
Quote:

>But wait - it gets even worse :(. Although it's possible
to active and work
>with the embedded document none of it's event handlers
are going to work
>(these are the procedures that respond to ComboBox

selection, CheckBox clicks
Quote:
>etc.) because there is already code running - your code

that just activated
Quote:
>the embedded document. You could possibly kludge around

it by activating the
Quote:
>embedded document and then having your code run the

documents Document_New or
Quote:
>Document_Open procedure to initialise the documents

controls. You would then
Quote:
>have to terminate your macro so the embedded documents
event handling
>procedures would work. At this stage the user is manually

ineracting with the
Quote:
>document. You've then got the problem of how do you get

programatic control
Quote:
>back. Essentially this can't happen unless the users

somehow starts more of
Quote:
>your code.

>Only the FormField Dropdown field has persistent values,

but is limited to a
Quote:
>maximum of 20 values.

>I hope the above is helpful even if it's not what you
wanted to hear!

>Cheers - Peter




Quote:

>> Peter;

>> Thank you very much for your assistance, it turned out
to
>> be quite helpful.  If I may impose upon you once more,
I
>> am trying to load this items with a second programs
which
>> opens the original document and then follows down the
>> inlineshapes list.

>> i.e.
>>   With objWordDoc
>>     For i = 1 To .InlineShapes.Count
>>       Debug.Print .InlineShapes.Item(i)
>>       .OLEFormat.ClassType
>>       Debug.Print .InlineShapes.Item(i)
>>       .OLEFormat.object.Name,
>>       Debug.Print .InlineShapes.Item(i)
>>       .OLEFormat.object.Value
>>     Next
>>   End With

>> When I get to the item I am looking for, in this case
>> combo boxes, how do I clear and reload their select
lists?

>> You really don't have to send me code samples, just
point
>> me in the right direction.

>> TIA

>> Joe Gabay

>.



Sun, 18 Sep 2005 04:56:11 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Updating a combo box list W/limit to list selected

2. Fill Combo List using Criteria selected in another Combo List

3. Fill Combo List using Criteria selected in another Combo List

4. How to list macro names in a combo box or a list box

5. Listing all tables or queries in a list/combo box

6. How to list macro names in a combo box or a list

7. How to list macro names in a combo box or a list

8. Use list from excel or access to populate combo/list box

9. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

10. Adding the alphabet in a list box or combo list

11. Selecting from list boxes and combo

12. Displaying selected list item in Style #2 combo box

 

 
Powered by phpBB® Forum Software