EXCEL VB从ACCESS提取数据问题。
SubPriceQuery()DimCnnDimrstDimSqlAsStringDimSTRDimstr11AsRangeDimiAsIntegerSTR1=Works...
Sub PriceQuery()
Dim Cnn
Dim rst
Dim Sql As String
Dim STR
Dim str11 As Range
Dim i As Integer
STR1 = Worksheets("a").Range("a1:a10")
Set Cnn = CreateObject("ADODB.Connection") '创建连接对象
Set rst = CreateObject("ADODB.Recordset") '创建数据集对象
Cnn.Open "Provider=Microsoft.Ace.OleDB.12.0;data Source=d:\学习.accdb" '打开数据源为access
For Each STR In STR1
i = 1
STR = Worksheets("a").Cells(i, 1)
Sql = "select * from [TABLE1] where 姓名 like '%" & STR & "%'"
Sheets("a").Cells(i, 2).CopyFromRecordset Cnn.Execute(Sql)
i = i + 1
Next STR
Cnn.Close '关闭连接,释放资源
Set Cnn = Nothing '关闭连接,释放资源
End Sub 展开
Dim Cnn
Dim rst
Dim Sql As String
Dim STR
Dim str11 As Range
Dim i As Integer
STR1 = Worksheets("a").Range("a1:a10")
Set Cnn = CreateObject("ADODB.Connection") '创建连接对象
Set rst = CreateObject("ADODB.Recordset") '创建数据集对象
Cnn.Open "Provider=Microsoft.Ace.OleDB.12.0;data Source=d:\学习.accdb" '打开数据源为access
For Each STR In STR1
i = 1
STR = Worksheets("a").Cells(i, 1)
Sql = "select * from [TABLE1] where 姓名 like '%" & STR & "%'"
Sheets("a").Cells(i, 2).CopyFromRecordset Cnn.Execute(Sql)
i = i + 1
Next STR
Cnn.Close '关闭连接,释放资源
Set Cnn = Nothing '关闭连接,释放资源
End Sub 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询