|
[广告] 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 & "\钢网数据库.accdb"
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 |
|