从VB6检查访问中的假期表中是不是存在日期
Posted
技术标签:
【中文标题】从VB6检查访问中的假期表中是不是存在日期【英文标题】:From VB6 checking if date exist in holiday table in access从VB6检查访问中的假期表中是否存在日期 【发布时间】:2014-10-16 15:08:52 【问题描述】:以下是我目前使用的函数,用于从发票日期中减去 20 天,然后如果是周末,则将该日期移至星期一。下一步是检查该日期是否在假日表中,以及是否相应地调整日期。问题是我正在对超过 30K 条记录运行此检查,并且需要很长时间。有没有更快的方法来完成同样的任务?提前致谢。
Public Function PrintDate(TheDate As Date) As Date
Dim OfficeClosed As Integer
Dim CheckDate As Date
Dim QSDate As String
Dim QS As String
OfficeClosed = False
TheDate = DateAdd("d", -20, TheDate)
Select Case Weekday(TheDate)
Case 1
CheckDate = DateAdd("d", 1, TheDate)
Case 7
CheckDate = DateAdd("d", 2, TheDate)
Case Else
CheckDate = TheDate
End Select
QSDate = CheckDate
QS = ""
QS = QS & "SELECT holidaydate "
QS = QS & "FROM tbl_holidays "
Set ado_objConn = New ADODB.Connection
ado_objConn.ConnectionTimeout = 130
ado_objConn.CommandTimeout = 130
ado_objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & _
gl_AutoFinance_Data_Loc & "';Persist Security Info=False"
ado_objConn.Open
Set ado_objRs8 = New ADODB.Recordset
ado_objRs8.Open QS, ado_objConn, , , adCmdText
With ado_objRs8
If Not .EOF Then
.MoveFirst
While Not .EOF
If ado_objRs8.Fields(0) = QSDate Then
OfficeClosed = True
End If
.MoveNext
Wend
End If
End With
Set ado_objRs8 = Nothing
Set ado_objConn = Nothing
If OfficeClosed = True Then
Select Case Weekday(CheckDate)
Case 2
PrintDate = DateAdd("d", 1, CheckDate)
Case 3
PrintDate = DateAdd("d", 1, CheckDate)
Case 4
PrintDate = DateAdd("d", 1, CheckDate)
Case 5
PrintDate = DateAdd("d", 1, CheckDate)
Case 6
PrintDate = DateAdd("d", 3, CheckDate)
End Select
Else
PrintDate = CheckDate
End If
End Function
【问题讨论】:
【参考方案1】:您应该在 from 子句中包含一个条件:
QS = ""
QS = QS & "SELECT holidaydate "
QS = QS & "FROM tbl_holidays "
QS = QS & "Where holidaydate = #" & QSDate & "#"
如果记录集返回一些记录,则 OfficeClosed = True。您必须删除循环中的条件,这样您就不必遍历记录集
【讨论】:
以上是关于从VB6检查访问中的假期表中是不是存在日期的主要内容,如果未能解决你的问题,请参考以下文章