combobox problem

  • Thread starter Thread starter Rbp9ad
  • Start date Start date
R

Rbp9ad

I have a userform for entry that has a combobox. Nothing appears in the drop
down list. I would like the combobox to add items enterd into as text in the
drop down menu if they are not already there. Is there a way to do this?
 
try this:

combobox name is cboTest


Private Sub cboTest_AfterUpdate()

Dim sTemp As String
Dim sList As Variant
Dim iLoop As Integer
Dim bFound As Boolean

sTemp = cboTest.Text

If Len(Trim(sTemp)) > 0 Then

If cboTest.ListCount = 0 Then
ReDim sList(0)
sList(0) = sTemp
cboTest.List = sList
Exit Sub
End If

'Replace with copymem api
'copy just the first dimension
ReDim sList(cboTest.ListCount)

For iLoop = 0 To cboTest.ListCount - 1
sList(iLoop) = cboTest.List(iLoop)
Next 'iLoop

'End replace with copymem api

For iLoop = 0 To cboTest.ListCount - 1
If StrComp(sTemp, sList(iLoop), vbTextCompare) = 0 Then
bFound = True
End If
Next 'iLoop

If Not bFound And cboTest.ListCount > 0 Then
ReDim Preserve sList(cboTest.ListCount)
sList(cboTest.ListCount) = sTemp
End If

cboTest.Clear
cboTest.List = sList

End If

End Sub
 
Alternatively you can simply use:

If not bFound then cboTest.Additem sTemp

in place of
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ComboBox Dropdown not under control 1
Locking down a combobox 10
ComboBox Queries 2
ComboBox problem 15
Combobox List Drop on Entry 3
Combobox filtering 2
UserForm ComboBox Date Format 1
Combobox selection 1

Back
Top