Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to fill several comboboxes in a frame with Form_Load() 2

Status
Not open for further replies.

JESTAR

Programmer
Feb 13, 2002
213
GB
Dim ctl as Control

[tt]For Each ctl In formHTML.fTable
If TypeOf ctl Is ComboBox Then
With ctl
.AddItem "%"
.AddItem "px"
.AddItem "pt"
.AddItem "mm"
.AddItem "cm"
.AddItem "in"
.ListIndex = 0
End With
End If
Next ctl[/tt]

Why won't that work? I get an error on the first line (For Each ...) saying:

"Object doesn't support this property or method"
 
And I'm using the MS Forms 2.0 Object Library combobox, if that matters.
 
Hi JESTAR,

Try this it should work:

For Each ctl In formHTML.Controls
If TypeOf ctl Is MSForms.ComboBox Then

Harleyquinn
 
Try this:
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is msforms.ComboBox And ctl.Container Is fTable Then
With ctl
.AddItem "%"
.AddItem "px"
.AddItem "pt"
.AddItem "mm"
.AddItem "cm"
.AddItem "in"
.ListIndex = 0
End With
End If
Next ctl
 
JESTAR,

DrJavaJoe is right I forgot specify that the comboboxes you wanted to populate were in fTable.

Harleyquinn
 
Hi. Thanks, but I'm still getting an error on:

"If TypeOf ctl..." etc.

saying "Object doesn't support this property or method"

Also, the combo boxes are a control array. Does that affect it?
 
I just tested the code above by placing a Frame control on the form renaming it fTable. Then adding The Forms 2.0 Object Library and adding 2 ComboBoxes, in a control array, to the frame. Run the code and it ran with no errors. So there must be more to it, can you post your exact code?
 
Hi again. Thanks for the help. Harleyquinn's code worked, but it fills all the combo boxes in every frame... this isn't a problem for the project though.

DJJ - your code was getting an error saying "fTable=0"
 
Use errortrapping.

Not all controls have the same properties and methods.
There must be a contyrol on your form/frame that doesn't support the statement you're using.
When you debug the code, you will be able to determine which control is generating the error by using a watch on ctl.
I met with the same problem but in the area of database fields that do not support the same properties depending on the type of field it is.


Merlin 's the name, and logic is my game...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top