trouble using dlast function

electricjelly

Registered User.
Local time
Today, 14:22
Joined
Apr 3, 2014
Messages
26
Hi I have been using the dlast function to look up the last record matching the inputted employee ID. I am trying to make it so that after looking up the last record access applies the opposite field to the [InOut] field however, it doesnt do anything and constantly applies a 0 (false) to the InOut field instead of doing the opposite.

Code:
On Error GoTo ErrorHandler

Dim LrecID As Integer
Dim LrecInOUT As Boolean

    LrecID = DLast("EmployeeID", "QryEmployeeClockIn", "[EmployeeID]=" & Me.EmployeeID.Value)
    LrecInOUT = DLast("InOut", "QryEmployeeClockIn", "[EmployeeID]=" & Me.EmployeeID.Value)
    
    If Me.EmployeeID.Value = LrecID And LrecInOUT = 0 Then
    InOut.Value = -1
    ElseIf Me.EmployeeID.Value = LrecID And LrecInOUT = -1 Then
    InOut.Value = 0
    ElseIf DLast("employeeID", "qryEmployeeClockIN", "[EmployeeID]=" & Me.EmployeeID.Value) = Null Then
    InOut.Value = -1
    End If
    
    TimeStamp.Value = 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
Also I have a query in which it is referencing and the query is set to ascending order by date inputted so that the last record is always the most recently inputted.
 
First take away in all places where you have the ".Value".
Second, check if LrecID and LrecInOUT actually receive/have the values you expected.
If nothing helps, post your database with some sample data, (zip it) + name of the form in which you've the problem.
 
Okay I removed the .Value from all the code, and I tried what you asked by using the same method but trying the pull the employee name into a msgbox however, i just received an error each time.
 

Attachments

... and I tried what you asked by using the same method but trying the pull the employee name into a msgbox however, i just received an error each time.
Yes because the name field in the table mostly is empty, (no name in it).
I put in the original code you showed in post #1, (except the .Value part), and it runs OK, (database attached again).
attachment.php
 

Attachments

  • Test1.accdb
    Test1.accdb
    440 KB · Views: 149
  • Tabledata.jpg
    Tabledata.jpg
    22 KB · Views: 470
hmmm... very odd because it works completely fine in my separate database that I uploaded, maybe there is a deeper issue with my larger database, thanks anyway at least I know now that my code works
 

Users who are viewing this thread

Back
Top Bottom