Results 1 to 4 of 4

Thread: no duplicate value in the comboBox(Resolved)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    Resolved 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
    Last edited by vivian2u; May 6th, 2005 at 09:53 AM.

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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:
    1. Private Sub Form_Load()
    2. rs.Open "select * from Course ", con, adOpenDynamic, adLockPessimistic
    3.  
    4. While Not rs.EOF
    5.     [b]For i = 0 To cbProg.ListCount - 1
    6.         If Not (rs("CourseTitle") = cbProg.List(i)) Then[/b]
    7.             cbProg.AddItem (rs("CourseTittle"))
    8.             rs.MoveNext
    9.         [b]End If
    10.     Next i[/b]
    11. Wend
    12.  
    13. End Sub
    Hope that helps,

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: no duplicate value in the comboBox

    Why not: SELECT DISTINCT CourseTitle FROM Course

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    Resolved Re: no duplicate value in the comboBox

    Hi,

    SELECT DISTINCT CourseTitle FROM Course is a good idea and problem solved. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width