Hi folks

I don't know what is happening with the following code. When there are no records in the table tblbatchdetails and the person try to insert a record then in the following function the error comes at dmax statement. But if I make this line comments and try to insert the record 2 or 3 times then the code works perfectly fine. If after that I remove the comments from that line and try to run the following code then it starts working absolutely fine. I think when there are no records in the table for particular date then the code gives problem otherwise dmax statement works fine.
Public Function Func3(AnyPerson As String, AnyStartTime As Date, AnyEndTime As Date) As String
 Dim dtmLower As Date
    Dim dtmUpper As Date
    dtmUpper = AnyStartTime
      dtmLower = nz(DMax("Finishtime", "tblbatchdetails", "Name='" & AnyPerson & "' and Date1=dateserial(" & Format(Date, "yyyy,mm,dd") & ")"))          
Dim dtmtotaltime As Date
    dtmtotaltime = dtmUpper - dtmLower
    If dtmtotaltime = dtmUpper Then
    Func3 = "00:00:00"
    Else
            Func3 = dtmtotaltime
            End If
       End Function
Any suggestions anyone please?

Thanks
Aman