|
-
Sep 15th, 2004, 08:24 AM
#1
Thread Starter
Junior Member
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
-
Sep 15th, 2004, 09:24 AM
#2
Lively Member
maybe this may help
maybe not
VB Code:
private sub combobox1.change()
count = 2
do while range("A" & count).value <> ""
if range("A" & count).value = combobox1.value then
combobox2.value = range("B" & count).value
goto exit
end if
count = count + 1
loop
exit:
end sub
-
Sep 16th, 2004, 06:25 AM
#3
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|