Results 1 to 3 of 3

Thread: ComboBox Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    16

    ComboBox Problem

    Hi!

    I have 2 ComboBox in Excel which I fill with ID and Name from a DB, see below:

    Private Sub Workbook_Open()

    szSQL = "SELECT PROJECT_ID, NAME " & _
    "FROM PROJECT "

    Set rsData = New ADODB.Recordset
    rsData.Open szSQL, oCn1, adOpenForwardOnly, adLockReadOnly, adCmdText

    If Not rsData.EOF Then

    Do While Not rsData.EOF

    ProjID = rsData.Fields(0).Value
    Name = rsData.Fields(1).Value

    Sheet2.ComboBox1.AddItem ProjID
    Sheet2.ComboBox2.AddItem Name

    rsData.MoveNext
    Loop
    Else
    MsgBox "Error: No records returned. ", vbCritical
    End If

    rsData.Close

    End Sub


    What I want to do is that when I choose the ProjID in ComboBox1, I want that ProjID's Name to be activated automatic in Combobox2.
    Does anyone have an idea how to to that?

    /B

  2. #2
    Lively Member
    Join Date
    Jun 2003
    Location
    france
    Posts
    71
    maybe this may help
    maybe not

    VB Code:
    1. private sub combobox1.change()
    2.  
    3. count = 2
    4. do while range("A" & count).value <> ""
    5. if range("A" & count).value = combobox1.value then
    6. combobox2.value = range("B" & count).value
    7. goto exit
    8. end if
    9. count = count + 1
    10. loop
    11. exit:
    12.  
    13. end sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    16
    Thansks a lot, that really helped.

    /B

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