PDA

View Full Version : Solved: Using of evaluate function



theopract
02-28-2008, 02:38 PM
I wonder if someone could help me to execute such a code using application.evaluate:

ComboBox3.AddItem "text"

where "3" is a variable (for example: Dim d As Integer) and text is text in a cell (for example: CStr(Range(Index(z) + LTrim(str(j)))) )

p.s. I tried to write it different ways, but everywhere faild, for instance:

application.evaluate ("UserForm1.ComboBox" + Trim(str(d + 1)) + ".AddItem " + Chr(34) + CStr(Range(Index(z + 1) + LTrim(str(j)))) + Chr(34))

Bob Phillips
02-28-2008, 04:49 PM
Me.Controls("ComboBox" & d).AddItem "text"

theopract
02-29-2008, 05:52 AM
xld, thank you very much! It really works =) You're genius!

Maybe you can also suggest me effective method how can I check if item already exists before adding it?

Bob Phillips
02-29-2008, 06:26 AM
You mean if the value exists within the combobox?

theopract
02-29-2008, 06:42 AM
You mean if the value exists within the combobox?
Yes, exactly.

Bob Phillips
02-29-2008, 07:05 AM
The correct way to do it is to check back in the control source, but here is a (really crappy IMO) way of doing it direct against the control itself



With ComboBox1
On Error Resume Next
.Value = "some value"
On Error GoTo 0
If .ListIndex = -1 Then MsgBox "Not found"
End With

theopract
02-29-2008, 07:54 AM
Tnx, xld! It works perfectly too. You helped me very much. I really do appreciate this.