Results 1 to 3 of 3

Thread: [RESOLVED] Populate word doc combos on load/open

  1. #1

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Resolved [RESOLVED] Populate word doc combos on load/open

    Hi,

    I'm trying to create a check list using word which basically consists of about 25 questions each of which will have a combo box (from control toolbox not forms toolbox) where users can select one of three options yes|no|n/a.

    I want to add a loop to the document_open() event to populate the combos but am getting an error

    Run time error 424: Object Required!

    When I click debug it breaks on the hilighted line below.
    myCtrl = Nothing and Controls is Empty???
    VB Code:
    1. Private Sub Document_Open()
    2.     Dim myCtrl As Control
    3.    
    4. [HL="#FFFF00"]    For Each myCtrl In Controls[/HL]
    5.         If InStr(1, myCtrl.Name, "cbo", vbTextCompare) Then
    6.             myCtrl.AddItem "Yes"
    7.             myCtrl.AddItem "No"
    8.             myCtrl.AddItem "N/A"
    9.         End If
    10.     Next
    11. End Sub

    Am I missing a reference or something?

    Any help will be gratefully received

    Cheers Al

  2. #2

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: Populate word doc combos on load/open

    I think I've made a bit of progress on this but don't know how to add the items

    now getting error -

    Compile Error: Method or data member not found
    When I take out the "AddItem" section and uncomment the msgbox all is okay
    VB Code:
    1. Dim myCtrl As InlineShape
    2.    For Each myCtrl In ActiveDocument.InlineShapes
    3.     If myCtrl.Type = wdInlineShapeOLEControlObject Then
    4.         If Left(myCtrl.OLEFormat.Object.Name, 3) = "cbo" Then
    5.             'msgbox "found: " & myCtrl.OLEFormat.Object.Name
    6.             With myCtrl
    7.                 [HL="#FFFF00"].AddItem "Yes"[/HL]
    8.                 .AddItem "No"
    9.                 .AddItem "N/A"
    10.             End With
    11.         End If
    12.     End If
    13. Next myCtrl

    Once again all help and or ideas will be welcome

  3. #3

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: Populate word doc combos on load/open

    Hi,

    I've managed to solve my problem

    VB Code:
    1. Private Sub Document_Open()
    2.     Dim myCtrl As InlineShape
    3.        For Each myCtrl In ActiveDocument.InlineShapes
    4.         If myCtrl.Type = wdInlineShapeOLEControlObject Then
    5.             If Left(myCtrl.OLEFormat.Object.Name, 3) = "cbo" Then
    6.                 'MsgBox "found: " & myCtrl.OLEFormat.Object.Name
    7.                 With myCtrl
    8.                     .OLEFormat.Object.AddItem "Yes"
    9.                     .OLEFormat.Object.AddItem "No"
    10.                     .OLEFormat.Object.AddItem "N/A"
    11.                 End With
    12.             End If
    13.         End If
    14.     Next myCtrl
    15. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width