deleting records within a certain timeframe

electricjelly

Registered User.
Local time
Today, 12:27
Joined
Apr 3, 2014
Messages
26
Hello,

I would like to make it so that if that last record inputted with the same ID was inputted within the past 5 minutes then it will not input the new record into the database. Im not sure how to code that time frame, but more importantly how to tell access to not do anything if the criteria does not match.

here is my code:
Code:
Dim LrecID As Variant
Dim LrecInOUT As Variant
Dim LrecDate As Variant
Dim Lname As String

    LrecID = DLast("EmployeeID", "QryEmployeeClockIn", "EmployeeID=" & Me.EmployeeID)
    LrecInOUT = DLast("InOut", "QryEmployeeClockIn", "EmployeeID=" & Me.EmployeeID)
    LrecDate = DLast("TimeStamp", "QryEmployeeClockIn", "EmployeeID=" & Me.EmployeeID)

    If Me.EmployeeID = LrecID And LrecInOUT = 0 Then
      InOut.Value = -1
    ElseIf Me.EmployeeID = LrecID And LrecInOUT = -1 Then
      InOut.Value = 0
    Else: InOut.Value = -1
    End If
 
' I was thinking something like this:
' If Me.EmployeeID = LrecID And LrecInOUT = 0 and LrecDate is not within  5 minutes ago Then 
' InOut.Value = -1
    
    
    
    TimeStamp = Now()

DoCmd.GoToRecord acForm, "FrmEmployeeClockIn", acNewRec

ExitSub:
    Exit Sub

ErrorHandler:
    On Error GoTo ErrorHandler2

ErrorHandler2:
    MsgBox "An error has occured, restart the form", vbOKOnly, "Error"
    Resume ExitSub
Thank you for any help in my dilemma.
 
Ive never heard of such a requirement but I'm thinking you need to put the code in the beforeupdate event and do a cancel event if the condition is true...
 
I assume lrecDate contains the last timestamp the employee clocked. So a new record may not be created within 5 minutes of that last timestamp.

This becomes

If DateAdd("n", 5, lrecDate) < Now() Then
'do nothing
Else
'save record
End If
 
I agree with Ken post#2.
For consideration, I have seen posts that suggest you should not use DLast (and DFirst). Better to use Max(..) if the field/record set up permits it. Typically a Date/Time datatype field in the record.

Good luck.
 

Users who are viewing this thread

Back
Top Bottom