|
Re:用DAO代替DLookup,测试了一下,速度提高了,也可以试一下在查询里用 加班:iif([1]="加",1,0)+iif([2]="加",1,0)+...+iif([31]="加",1,0),不过录入太烦了,我也没试过:(。
Function KSum(DD As String, ID As Integer) As Integer
Dim h, J As Integer
Dim rst As DAO.Recordset
Set rst = CurrentDb().OpenRecordset("select * from 考勤表SUB")
rst.FindFirst "[ID]=" & ID
J = 0
For h = 1 To 31
On Error GoTo ER
' MsgBox (DLookup("[" & CStr(h) & "]", "考勤表SUB", "[ID]=" & ID))
kk = IIf(rst("" & h & "") = DD, 1, 0)
J = J + kk
Next h
KSum = J
Exit Function
ER:
If Err() = 94 Then
kk = 0
Else
MsgBox (Err())
End If
Resume Next
End Function
|
|