[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:
Private Sub Document_Open()
Dim myCtrl As Control
[HL="#FFFF00"] For Each myCtrl In Controls[/HL]
If InStr(1, myCtrl.Name, "cbo", vbTextCompare) Then
myCtrl.AddItem "Yes"
myCtrl.AddItem "No"
myCtrl.AddItem "N/A"
End If
Next
End Sub
Am I missing a reference or something?
Any help will be gratefully received
Cheers Al
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:
Dim myCtrl As InlineShape
For Each myCtrl In ActiveDocument.InlineShapes
If myCtrl.Type = wdInlineShapeOLEControlObject Then
If Left(myCtrl.OLEFormat.Object.Name, 3) = "cbo" Then
'msgbox "found: " & myCtrl.OLEFormat.Object.Name
With myCtrl
[HL="#FFFF00"].AddItem "Yes"[/HL]
.AddItem "No"
.AddItem "N/A"
End With
End If
End If
Next myCtrl
Once again all help and or ideas will be welcome
Re: Populate word doc combos on load/open
Hi,
I've managed to solve my problem
VB Code:
Private Sub Document_Open()
Dim myCtrl As InlineShape
For Each myCtrl In ActiveDocument.InlineShapes
If myCtrl.Type = wdInlineShapeOLEControlObject Then
If Left(myCtrl.OLEFormat.Object.Name, 3) = "cbo" Then
'MsgBox "found: " & myCtrl.OLEFormat.Object.Name
With myCtrl
.OLEFormat.Object.AddItem "Yes"
.OLEFormat.Object.AddItem "No"
.OLEFormat.Object.AddItem "N/A"
End With
End If
End If
Next myCtrl
End Sub