|
楼主 |
发表于 2021-7-21 09:34
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 查询() '用户定义类型未定义:“工具”-"引用"-"Microsoft ActiveX Data Object 6.1勾选
On Error Resume Next
Dim SQL As String, arr, brr(1 To 100, 1 To 6)
a = InputBox("输入需要查询的产品型号:", "型号", "GS536")
Set cnn = CreateObject("ADODB.Connection") '创建数据库连接
cnn.Open "provider=Microsoft.ace.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\jjamxspl.mdb;Jet OLEDB:Database Password=2012"
SQL = "SELECT * FROM 综合数据库 where 单据类型 like'%" & a & "%'" '定义SQL查询命令字符串"
arr = cnn.Execute(SQL).GetRows '不加GetRows只能查出来一个值
cnn.Close
Set cnn = Nothing
For j = 0 To UBound(arr, 2)
n = n + 1: w = 0
For i = 0 To UBound(arr)
w = w + 1
brr(n, w) = arr(i, j)
Next
Next
[a2].Resize(UBound(brr), 5) = brr
End Sub
运行不了 |
|