|
t2和T3是时间格式,其他条件是文本
Sub zp_jihuacaxun()
Dim conn As Object, SQL$, TiaoJian$, ZhiDuan$, eRow%
If Range("t3") = "" And Range("t2") = "" And Range("t5") = "" And Range("t7") = "" And Range("t9") = "" Then: MsgBox "条件单元格不能全部为空", , "操作提示": Exit Sub
If Range("t3") <> "" And Range("t5") <> "" Then
sn = Range("t5").Value: cn = Range("t3").Value
Else
If Range("t3") <> "" And Range("t5") = "" Then
sn = "%": cn = Range("t3").Value
cnn = "%": cn = Range("t3").Value
Else
cn = "%": sn = Range("t5").Value
End If
End If
[A2:k65536].ClearContents
Set conn = CreateObject("adodb.connection")
conn.Provider = "microsoft.jet.oledb.4.0"
conn.Open ThisWorkbook.Path & "\Concession.mdb"
SQL = "select 市场号,订单号,制造号,厂家,图号,订单数,发交时间,大类,轴管,生产时间,下料下达,任务车间,任务班组 from sheet2 where 发交时间 >= #" & cn & "# and 图号 Like '" & sn & "' And 任务车间 = '装配' And 任务班组 = range('t9').value "
Sheet7.[A2].CopyFromRecordset conn.Execute(SQL)
conn.Close
Set conn = Nothing
eRow = Range("A65535").End(xlUp).Row
If eRow = 1 Then
MsgBox "数据库内没有此查询条件的信息,请确认查询信息是否正确。", , "操作提示"
End If
Range("I2").Select
End Sub |
|