no duplicate value in the comboBox(Resolved)
hi,
I want to avoid the duplicate course tittle in the comboBox when I load the form. It is allow to add new course tittle if there is not in the combobox. I have try to search from the examples but none of them are relevant. Please help.
Private Sub Form_Load()
rs.Open "select * from Course ", con, adOpenDynamic, adLockPessimistic
while Not rs.EOF
cbProg.AddItem (rs("CourseTittle"))
rs.MoveNext
Wend
end sub
Re: no duplicate value in the comboBox
I don't think its possible through SQL, so you might have to do something like this:
VB Code:
Private Sub Form_Load()
rs.Open "select * from Course ", con, adOpenDynamic, adLockPessimistic
While Not rs.EOF
[b]For i = 0 To cbProg.ListCount - 1
If Not (rs("CourseTitle") = cbProg.List(i)) Then[/b]
cbProg.AddItem (rs("CourseTittle"))
rs.MoveNext
[b]End If
Next i[/b]
Wend
End Sub
Hope that helps,
Phreak
Re: no duplicate value in the comboBox
Why not: SELECT DISTINCT CourseTitle FROM Course
Re: no duplicate value in the comboBox
Hi,
SELECT DISTINCT CourseTitle FROM Course is a good idea and problem solved. Thanks :wave: