electricjelly
Registered User.
- Local time
- Today, 10:40
- Joined
- Apr 3, 2014
- Messages
- 26
Hi I am trying to use an SQL statement to input data into another table but I constantly receive a "invalid procedure call or argument" I have tried several different things to attempt remedying the problem, but nothing seems to solve the issue. I assume that there is something that I am just not seeing because of my inexperienced eyes. Thank you for any help.
The actual code where I receive the error is in red
The actual code where I receive the error is in red
Code:
Private Sub EmployeeID_AfterUpdate()
On Errror GoTo ErrorHandler
Dim LrecID As Variant
Dim LrecInOUT As Variant
Dim LrecDate As Variant
Dim Ldate As Variant
Dim rstEmployee As DAO.Recordset
Dim dbsNatCat As DAO.Database
Dim strSQL As String
Dim ErrSQL As String
Dim ErrDescription As String
Dim InsSQL As String
LrecID = DLast("EmployeeID", "QryEmployeeClockIn", "EmployeeID=" & Me.EmployeeID)
LrecInOUT = DLast("InOut", "QryEmployeeClockIn", "EmployeeID=" & Me.EmployeeID)
LrecDate = DMax("TimeStamp", "QryEmployeeClockIn", "EmployeeID=" & Me.EmployeeID)
Ldate = DateAdd("n", 5, LrecDate)
'this set of codes is for the declarations for thebigbadwolf
strSQL = "SELECT * FROM QryEmployeeClockIn ORDER BY EmployeeID, TimeStamp"
Set dbsNatCat = CurrentDb
Set rstEmployee = dbsNatCat.OpenRecordset(strSQL, dbOpenDynaset)
If LrecInOUT = 0 And Ldate < Now() And LrecDate > Date - 1 Then
InOut.Value = -1
ElseIf LrecInOUT = -1 And LrecDate > Date - 1 Then 'And Ldate < Now()
InOut.Value = 0
GoTo CalcHours
ElseIf LrecInOUT = 0 And Ldate > Now() Then
GoTo TheBigBadWolf
ElseIf LrecInOUT = -1 And Ldate > Now() Then
GoTo TheBigBadWolf
Else: InOut.Value = -1
End If
TimeStamp = Now()
DoCmd.GoToRecord acForm, "FrmEmployeeClockIn", acNewRec
GoTo ExitSub
CalcHours:
[SIZE=3][COLOR=Red] DoCmd.RunSQL "INSERT INTO tblhoursworked(FldHoursWorked,FldEmployeeID,FldDateInputted) " _
& " VALUES ('" & DateDiff(hh, LrecDate, Now()) & "', '" & Me.EmployeeID.Value & "',#" & Now() & "#)"[/COLOR][/SIZE]
TimeStamp = Now()
'this is where the records are deleted
TheBigBadWolf:
rstEmployee.Delete
DoCmd.GoToRecord acForm, "FrmEmployeeClockIn", acNewRec
GoTo Cleanup
'this code deletes the previous record from thebigbadwolf based on whether not not timestamp is filled
Cleanup:
DoCmd.SetWarnings False 'will turn off the popup warnings
DoCmd.RunSQL "DELETE FROM tblEmployeeClockIn " & _
"WHERE TimeStamp IS NULL;"
DoCmd.SetWarnings True 'will turn the popup warnings on
GoTo ExitSub
CleanSlate:
DoCmd.RunCommand acCmdUndo
Resume ExitSub
ExitSub:
Exit Sub
ErrorHandler:
On Error GoTo ErrorHandler2
ErrorHandler2:
'this logs the error into a table without stopping the flow of the form
ErrDescription = Chr(34) & Err.Description & Chr(34)
ErrSQL = "INSERT INTO tblErrorLog (ErrDate, CompName, UsrName, " _
& " ErrNumber, ErrDescription, ErrModule, EmployeeID, TimeInOut)" _
& " VALUES(#" & Now() & "#, '" & Environ("ComputerName") _
& "', '" & CurrentUser & "', " & Err.Number _
& ", " & ErrDescription & ", '" & VBE.ActiveCodePane.CodeModule & "', '" & Me.EmployeeID _
& "', '" & Me.TimeStamp & "')"
Debug.Print ErrSQL
DoCmd.SetWarnings False
DoCmd.RunSQL ErrSQL
DoCmd.SetWarnings True
GoTo CleanSlate
End Sub
Last edited: