-
ComboBox retrieval.
Hello everyone.
I've been searching help files and also browsing the net trying to find out how I can specify a certain index within a combobox. To add to the combo box I used combobox1.additem
What I'm trying to do is get the index so I can have a loop like the following so that no repeats are allowed in the combobox.
[vba]private sub addWord()
dim i as integer
i = 1
dim count as integer
count = 0
do while i < combobox1.itemcount
if strcomp(combobox1(i), textbox1.text, vbtextcompare) = 1 then
msgbox("Sorry word already exists")
else
count = count + 1
end if
i = i + 1
loop
if count = combobox1.itemcount then
combobox1.Additem = textbox1.text
end if
end sub[/vba]
Also is there a more efficient way?
Any help greatly appreciated.
-
I believe you want to check against "0" to check if its equal.
Mark
[vba]Private Sub cmdAddEntry_Click()
Dim intCnt As Integer, _
bolDup As Boolean
If cboUnique.ListCount > 0 Then
For intCnt = 0 To cboUnique.ListCount - 1
'// I believe you want ...=0 to check.//
If StrComp(cboUnique.List(intCnt), _
txtHolder.Value, vbTextCompare) = 0 Then
'duplicate so disregard
txtHolder.Value = Empty
bolDup = True
MsgBox "Already entered", 0, ""
Exit For
End If
Next
End If
If Not bolDup Then
cboUnique.AddItem txtHolder.Value
txtHolder.Value = Empty
End If
End Sub[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules