|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 数据()
Dim cnn, rs, sql
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
With cnn
.Provider = "microsoft.ace.oledb.12.0"
.ConnectionString = ThisWorkbook.Path & "\数据库.accdb"
.Open
End With
bc = [a2]: scx = [b2]: pz = [c2]
sql = "select 班次,生产线,品种 from 生产命令单 where 班次='" & bc & "' and 生产线='" & scx & "' and 品种='" & pz & "'"
rs.Open sql, cnn, 3, 2
[d2] = rs.RecordCount
Range("a3").CopyFromRecordset rs
cnn.Close
Set cnn = Nothing
End Sub
画个按钮,把代码贴进去 |
|