Dim policeman As Integer
Dim Kuvasz As String
policeman = InputBox("请输入查询编号!", "输入编号进行查询", 1)
Kuvasz = "SELECT 编号 from Temresult where 编号=" & policeman
Call OpenAdoRecordset(Kuvasz, vsoReco)
enquiry.Label21.Caption = policeman
enquiry.Label3.Caption = vsoReco.Fields("台区名称").Value
enquiry.Label5.Caption = vsoReco.Fields("总供电量").Value
其中openAdoRecordset是:
Public Sub OpenAdoRecordset(ByVal strSQL As String, vsoReco As ADODB.Recordset)
Dim vsoConn As ADODB.Connection
Dim strcnn As String
Set vsoConn = New ADODB.Connection
Set vsoReco = New ADODB.Recordset
strcnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\WW\data.mdb"
vsoConn.Open strcnn
Set vsoReco.ActiveConnection = vsoConn
vsoReco.CursorType = adOpenStatic
vsoReco.LockType = adLockOptimistic
vsoReco.Open strSQL
End Sub
数据表Temresult的编号字段是整型,按编号查询到一条指定的记录。