|
Sub 查询()
Set mycon = New ADODB.Connection
Dim constr As String
constr = "provider = Microsoft.Jet.OLEDB.4.0;data source = " + ThisWorkbook.Path & " \db1.mdb"
mycon.connectionstring = constr
Set mycmd = New ADODB.Command
mycon.Open
mycmd.activeconnection = mycon
mycmd.CommandText = "select * from 查询 where (a列) = '" & Range("a1").Value & "' And (b列) '" & Range("b1") & "'"
Dim result As ADODB.Recordset
Set result = mycmd.exectute()
Dim index As Integer
index = 3
Do While Not result.EOF
With Worksheets("sheet1")
.Cells(index, 1).result.fields("a列").Value
.Cells(index, 2).result.fields("b列").Value
End With
index = index + 1
result.Movenext
Loop
mycon.colse
End Sub |
|