A
alexsas
Hi! I try to develop a search interface by using Excel, but I have no idea
how can I make the SQL where clause become dynamic. Thanks a lot.
The VBA code is below:
Sub ado()
Dim AlexCon As ADODB.Connection
Dim AlexRS As ADODB.Recordset
Af = Cells("a10").Value
Ase = Cells("b10").Value
Set AlexCon = New ADODB.Connection
AlexCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\test.mdb"
Set AlexRS = New ADODB.Recordset
With AlexRS
.ActiveConnection = AlexCon
.Source = "SELECT * FROM test WHERE B=" &Af &"Or A=" &Ase
.Open
End With
Range("A1").CopyFromRecordset AlexRS
AlexRS.Close
Set myRecSet = Nothing
AlexCon.Close
Set AlexCon = Nothing
End Sub
how can I make the SQL where clause become dynamic. Thanks a lot.
The VBA code is below:
Sub ado()
Dim AlexCon As ADODB.Connection
Dim AlexRS As ADODB.Recordset
Af = Cells("a10").Value
Ase = Cells("b10").Value
Set AlexCon = New ADODB.Connection
AlexCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\test.mdb"
Set AlexRS = New ADODB.Recordset
With AlexRS
.ActiveConnection = AlexCon
.Source = "SELECT * FROM test WHERE B=" &Af &"Or A=" &Ase
.Open
End With
Range("A1").CopyFromRecordset AlexRS
AlexRS.Close
Set myRecSet = Nothing
AlexCon.Close
Set AlexCon = Nothing
End Sub