如何获取下拉框中本记录的其它字段?
此贴中是用ADODC控件(https://bbs.bccn.net/viewthread.php?tid=487010&extra=&highlight=combo&page=1),现在想直接用代码,错误如下:附代码
程序代码:
Option Explicit Dim cn As New ADODB.Connection Dim rskh As ADODB.Recordset Dim i% Private Sub Combo1_Click() '与下拉框对应的字段名赋给文本框 rskh.Open "select * from kh where 简称='" & Combo1.Text & "'", cn, adOpenKeyset, adLockOptimistic Text1.Text = rskh.Fields("代码") End Sub Private Sub Form_Load() '连接数据库 If cn.State = 0 Then cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\ht.mdb" End If '加载客户下拉框 Set rskh = New ADODB.Recordset rskh.Open "select * from kh", cn, adOpenKeyset, adLockOptimistic If rskh.RecordCount > 0 Then For i = 0 To rskh.RecordCount - 1 Combo1.AddItem rskh.Fields("简称") rskh.MoveNext Next i End If rskh.Close End Sub
附件为所有文件
gytest.zip
(26 KB)
请指教,不胜感激!!!