我想计算一个电话号码,Datecall
,[Username]
是表格BCKHDY
的字段名称,但为什么numbercall
始终等于0.如果我删除{{ 1}},代码运行,这意味着AND DateCall= #" & DateFrom & "#
有问题。怎么了?
Datecall
答案 0 :(得分:1)
你在这里错过了一个空格:
mydept & "AND
应该是
mydept & " AND
只有字符串中的空格才算。如果您忘记了空格,则标准将包含1And
您还需要将日期格式设置为yyyy-MM-dd或MM / dd / yyyy:
"[UserName] = " & mydept & " AND DateCall >= #" & Format(DateFrom, "yyyy-MM-dd") & "#")
答案 1 :(得分:1)
你不必两次调用DLookup,声明所有变量,你可能在DCount中错误的字段上过滤:
Private Sub txtnbCall_Click()
Dim mydept As Variant
Dim DateFrom As Date
Dim User As String
DateFrom = Me!txtfrom.Value
User = Forms![Navigation form]![txtLogin].Value
mydept = DLookup("Deptname", "tblUser", "UserLogin = '" & User & "'")
If Not IsNull(mydept) Then
Me!txtnbCall.Value = numbercall(mydept, DateFrom)
End If
End Sub
Public Function numbercall(ByVal mydept As Integer, _
ByVal DateFrom As Date) As Integer
numbercall = DCount("*", "BCKHDY", _
"[Deptname] = " & mydept & " AND DateCall >= #" & Format(DateFrom, "yyyy\/mm\/dd") & "#")
End Function