Sub test() '提取数据
Dim cnn As New ADODB.Connection '连接
Dim RS As New ADODB.Recordset
Dim SQL As String
Dim tblName '(请问这些是什么类型
Dim dbAddr
Dim dayu
Dim xiaoyu
Dim fildName
Dim j ''请问这些是什么类型)
dayu = Cells(2, 9) '2019/5/1 查询单元格日期
xiaoyu = Cells(2, 10) '2019/6/5 查询单元格日期
dbAddr = ThisWorkbook.Path & "\生产数据.accdb"
tblName = "Sheet1"
With cnn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open "Data Source=" & dbAddr & "ersist Security Info=False;Jet OLEDB:DataBase Password=123;"
End With
SQL = "Select * from " & tblName & " where 订单日期>= #" & dayu & "# and 订单日期<= #" & xiaoyu & "#"
' SQL = "Select * from " & tblName & " where 部门 in('生技部')" 'in('生技部','aa')"
Set RS = cnn.Execute(SQL)
Dim sht
Dim fildNum
Set sht = ThisWorkbook.Worksheets("Sheet3")
sht.Range("A4:Y1048576").ClearContents '清除
fildNum = RS.Fields.Count
For j = 0 To fildNum - 1 Step 1
fildName = RS.Fields(j).Name
sht.Cells(3, j + 1) = fildName
Next j
sht.Cells(4, 1).CopyFromRecordset RS
cnn.Close
Set RS = Nothing
Set cnn = Nothing
End Sub