PDA

View Full Version : Solved: fixing code - automaticaly handling with many of combobox, labels...



danovkos
09-20-2011, 05:33 AM
Hi,
pls. i try to handling with combobox and labels in userform. I try e.g. load list of values to combobox if any condition is true. Problem is, that i have to work with many of combobox (combobox1, combobox2, combobox3...) and also with many labels (label1, label2...)

I tried to set my combobox and labels with this macro, but it doesnt works.

For i = 1 To 6
produktik = "COMBO_produkt" & i
OPUcko = "COMBO_OPU" & i
CIFko = "Label_cif" & i
If CIFko.Value <> "" Then
produktik.list = Workbooks(PrehladyNAMEVp).Worksheets("Krieš").Range("BD2:BD31").Value
OPUcko.list = Workbooks(PrehladyNAMEVp).Worksheets("Krieš").Range("Q2:W103").Value
End If

Next i


COMBO_produkt is name of my combo in userform and Label_cif is name of my label in userform.

any suggestions?
thx a lot

Aflatoon
09-20-2011, 06:02 AM
You need to use the Controls collection:
For i = 1 To 6
Set produktik = Me.Controls("COMBO_produkt" & i)
Set OPUcko = Me.Controls("COMBO_OPU" & i)
Set CIFko = Me.Controls("Label_cif" & i)
If CIFko.Value <> "" Then
produktik.list = Workbooks(PrehladyNAMEVp).Worksheets("Krieš").Range("BD2:BD31").Value
OPUcko.list = Workbooks(PrehladyNAMEVp).Worksheets("Krieš").Range("Q2:W103").Value
End If

Next i

danovkos
09-20-2011, 06:11 AM
thx for help,
but it make error
"Object doesnt support this propperty or method"

on this line
If CIFko.Value <> "" Then

:(

Aflatoon
09-20-2011, 06:23 AM
Apologies - you need the Caption property rather than Value for a label.

danovkos
09-20-2011, 06:41 AM
it works perfect
thank you very much

only one question,
if i want to use this control with checkbox....

then this line
Set cbox = Me.Controls("CB_preradenie1" & ii)
return error
"could not find specific object"

how can i use this please?
i only want to hide or show chceckbox
thx

danovkos
09-20-2011, 06:44 AM
sorry my bad...i got it...