我习惯用; Rs.Open "select * from employees", CN, adOpenDynamic, adLockOptimistic Do Until Rs.EOF Combo1.AddItem Rs.Fields("FirstName") Rs.MoveNext Loop
DataComBo也很好用 Private Sub txtHamletCodei_Click(Area As Integer) '========================== sQuery = "SELECT * FROM tblhamletcodei where hamletcode='" & txtHamletCode.Text & "'" Set rsCmms = cnnCMMS.Execute(sQuery) Set txtHamletCodei.RowSource = rsCmms txtHamletCodei.ListField = "hamletcodei" '========================== End Sub
Do Until Rs.EOF
Combo1.AddItem Rs.Fields("FirstName")
Rs.MoveNext
Loop
Private Sub txtHamletCodei_Click(Area As Integer)
'==========================
sQuery = "SELECT * FROM tblhamletcodei where hamletcode='" & txtHamletCode.Text & "'"
Set rsCmms = cnnCMMS.Execute(sQuery)
Set txtHamletCodei.RowSource = rsCmms
txtHamletCodei.ListField = "hamletcodei"
'==========================
End Sub
objrs.open "sql",conn,3,1
DataComBo.ListField = ""
DataComBo.DataField = ""
DataComBo.DataSource = objrs
DataComBo.RowSource = objrs
DataComBo.ListField = "字段"
DataComBo.DataField = "字段"
用combobox可以循环赋值
你明智的选择