|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Public Function check_demand(product As String, workingDate As Date) As Boolean
- Dim Conn As Object, Rst As Object, strPath As String
- Dim strConn As String, strSQL As String
- Dim lngCount As Long
- Dim blIsFind As Boolean
- Dim demand_date As Date
-
- Set Conn = CreateObject("ADODB.Connection")
- Set Rst = CreateObject("ADODB.Recordset")
- strPath = ThisWorkbook.FullName '设置工作簿的完整路径和名称
- Select Case Application.Version * 1 '设置连接字符串,根据版本创建连接
- Case Is <= 11
- strConn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & strPath
- Case Is >= 12
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strPath & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
- End Select
- Conn.Open strConn '打开数据库链接
- '''''''''''''''''''''''''''''''''
- strSQL = "SELECT Max([Delivery Date]) As [最后日期] " & _
- "FROM [Demand$] " & _
- "WHERE module_type = '17HLLeiCHNG'"
- Rst.Open strSQL, Conn, 3, 1 '执行查询,并将结果输出到记录集对象
- lngCount = Rst.RecordCount
- If lngCount = 0 Then
- blIsFind = False
- Else
- demand_date = Rst("最后日期").Value & ""
- If demand_date = workingDate Then
- blIsFind = True
- Else
- blIsFind = False
- End If
- End If
-
- Set Rst = Nothing
- Set Conn = Nothing
-
- check_demand = blIsFind
-
- End Function
复制代码 |
|