用ado+sql语句 sql="select 序号,城市 from 表1 where 序号='" & text1.text & "'" Set rs = New ADODB.Recordset Set rs = cnn.Execute(sql) text2.text=rs(1).value
'引用 Microsoft ActiveX data objicts 2.* Private Sub Text1_Change() Dim sql As String Dim db As ADODB.Connection Dim rs As ADODB.Recordset Set db = New ADODB.Connection Set rs = New ADODB.Recordset If Len(Text1.Text) <> 3 Then Exit Sub db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\aaa.mdb;Persist Security Info=False;" sql = "select 序号,城市 from 表1 where 序号='" & Text1.Text & "'" rs.Open sql, db, adOpenKeyset, adLockOptimistic If rs.RecordCount > 0 Then Text2.Text = rs(1).Value Else Text2.Text = "" End If End Sub
sql="select 序号,城市 from 表1 where 序号='" & text1.text & "'"
Set rs = New ADODB.Recordset
Set rs = cnn.Execute(sql)
text2.text=rs(1).value
Private Sub Text1_Change()
Dim sql As String
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
If Len(Text1.Text) <> 3 Then Exit Sub
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\aaa.mdb;Persist Security Info=False;"
sql = "select 序号,城市 from 表1 where 序号='" & Text1.Text & "'"
rs.Open sql, db, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Text2.Text = rs(1).Value
Else
Text2.Text = ""
End If
End Sub