G
Greg Maxey
Hi,
If I open a new document, insert a Combobox with the Controls toolbar, name the combobox "myCB" and then enter the code:
Sub Test()
myCB.AddItem "A"
End Sub
in the "ThisDocument" area of Project(Document1)
As I enter that code and type myCB., the dropdown list appears so I can select "AddItem," and the code runs with no error.
Now if I add a module "Module1" and enter that same code, the dropdown doesn't appear as I type myCB. and when I run the code, I get the error:
Compile error: Variable not defined on the myCB statement.
Now if I enter this code in the module it works:
Sub Test()
Dim myCB As ComboBox
Set myCB = ActiveDocument.myCB
With myCB
.Clear
.AddItem "A"
End With
End Sub
However as I type Set myCB = ActiveDocument. (the dropdown list does not appear with the option to select myCB
So I guess my question is, Can someone explain what is going on under the hood in Word here and what is the proper way to declare and then use a control in a Word form.
Thanks
If I open a new document, insert a Combobox with the Controls toolbar, name the combobox "myCB" and then enter the code:
Sub Test()
myCB.AddItem "A"
End Sub
in the "ThisDocument" area of Project(Document1)
As I enter that code and type myCB., the dropdown list appears so I can select "AddItem," and the code runs with no error.
Now if I add a module "Module1" and enter that same code, the dropdown doesn't appear as I type myCB. and when I run the code, I get the error:
Compile error: Variable not defined on the myCB statement.
Now if I enter this code in the module it works:
Sub Test()
Dim myCB As ComboBox
Set myCB = ActiveDocument.myCB
With myCB
.Clear
.AddItem "A"
End With
End Sub
However as I type Set myCB = ActiveDocument. (the dropdown list does not appear with the option to select myCB
So I guess my question is, Can someone explain what is going on under the hood in Word here and what is the proper way to declare and then use a control in a Word form.
Thanks