Ok, this is how I made it work. Pasting, but also attaching screenshot with an error message.
link to previous thread on this: http://www.access-programmers.co.uk/forums/showthread.php?t=287026
I'm now able to put date/time in database in correct format. Now when I try to confirm that program does not enter duplicate values, it comes up with strange results!! Either, it doesn't add duplicate values because criteria is matched, OR, it gives me an error message telling 'Data Type Dismatch...', OR, it enters all duplicate values in the table. 'Data Type Dismatch...' error sometimes disappears for few minutes once i restart the database.
I'm scratching my head over this now and spent my full day to solve this, but can't. Could someone please help by looking at the code and tell what am I doing wrong!!
Thanks,
K
Dim i As Integer
Dim strDate As String '**This variable is used to convert date into proper string format, against the required date format we need for the database
Dim tmp As Date
Debug.Print DLast("format(Assignment_Date, 'long date')", "tblEmployee_WorkPack", "EmployeeID = " & Me.EmployeeID)
Debug.Print DateValue(Me.txtFromDate)
tmp = Format(Me.txtFromDate, "yyyy-mm-dd")
strDate = tmp & " 06:30:00 AM"
If IsNull(DLookup("EmployeeID", "tblEmployee_WorkPack", "DateValue(Assignment_Date) = DateValue(#" & Me.txtFromDate & "#) And EmployeeID = " & Me.EmployeeID)) Then
Me.Assignment_Date = Me.txtFromDate
'**This saves values in SignIn time/date as soon as Supervisor is assigned to a job for a specific day
CurrentDb.Execute "INSERT INTO tblEmp_Clocked_Time (EmployeeID, SignedIN) " & _
"VALUES(" & Me.EmployeeID & ", '" & strDate & "') "
DoCmd.RunCommand acCmdSaveRecord
End If
For i = 1 To DateDiff("d", Me.txtFromDate, Me.txtToDate)
d = DateValue(DateAdd("d", i, Me.txtFromDate))
'Debug.Print d
'Debug.Print DLookup("assignment_Date", "tblEmployee_WorkPack", "EmployeeID = " & Me.EmployeeID)
strDate = d & " 06:30:00 AM"
'**This compares if record is already present for the specified Supervisor on specific Date. If not, it continues by adding data
If IsNull(DLookup("EmployeeID", "tblEmployee_WorkPack", "DateValue(Assignment_Date) = DateValue(DateAdd('d', " & i & ", #" & Me.txtFromDate & "#)) And EmployeeID = " & Me.EmployeeID)) Then
CurrentDb.Execute "INSERT INTO tblemployee_Workpack ( EmployeeID, Role_Type, Assignment_Date, Working_Hours, Lost_Hours, Rest_Hours, Notes) " & _
"VALUES(" & Me.EmployeeID & ", " & Me.Role_Type & ", '" & strDate & "', " & _
"" & Me.Working_Hours & ", " & Me.Lost_Hours & ", " & Me.Rest_Hours & ", Nz('" & Me.Notes & "', '" & vbNullString & "'))"
'**This saves values in SignIn time/date as soon as Supervisor is assigned to a job for a specific day
CurrentDb.Execute "INSERT INTO tblEmp_Clocked_Time (EmployeeID, SignedIN) " & _
"VALUES(" & Me.EmployeeID & ", '" & strDate & "')"
End If
Next i
link to previous thread on this: http://www.access-programmers.co.uk/forums/showthread.php?t=287026
I'm now able to put date/time in database in correct format. Now when I try to confirm that program does not enter duplicate values, it comes up with strange results!! Either, it doesn't add duplicate values because criteria is matched, OR, it gives me an error message telling 'Data Type Dismatch...', OR, it enters all duplicate values in the table. 'Data Type Dismatch...' error sometimes disappears for few minutes once i restart the database.
I'm scratching my head over this now and spent my full day to solve this, but can't. Could someone please help by looking at the code and tell what am I doing wrong!!
Thanks,
K
Dim i As Integer
Dim strDate As String '**This variable is used to convert date into proper string format, against the required date format we need for the database
Dim tmp As Date
Debug.Print DLast("format(Assignment_Date, 'long date')", "tblEmployee_WorkPack", "EmployeeID = " & Me.EmployeeID)
Debug.Print DateValue(Me.txtFromDate)
tmp = Format(Me.txtFromDate, "yyyy-mm-dd")
strDate = tmp & " 06:30:00 AM"
If IsNull(DLookup("EmployeeID", "tblEmployee_WorkPack", "DateValue(Assignment_Date) = DateValue(#" & Me.txtFromDate & "#) And EmployeeID = " & Me.EmployeeID)) Then
Me.Assignment_Date = Me.txtFromDate
'**This saves values in SignIn time/date as soon as Supervisor is assigned to a job for a specific day
CurrentDb.Execute "INSERT INTO tblEmp_Clocked_Time (EmployeeID, SignedIN) " & _
"VALUES(" & Me.EmployeeID & ", '" & strDate & "') "
DoCmd.RunCommand acCmdSaveRecord
End If
For i = 1 To DateDiff("d", Me.txtFromDate, Me.txtToDate)
d = DateValue(DateAdd("d", i, Me.txtFromDate))
'Debug.Print d
'Debug.Print DLookup("assignment_Date", "tblEmployee_WorkPack", "EmployeeID = " & Me.EmployeeID)
strDate = d & " 06:30:00 AM"
'**This compares if record is already present for the specified Supervisor on specific Date. If not, it continues by adding data
If IsNull(DLookup("EmployeeID", "tblEmployee_WorkPack", "DateValue(Assignment_Date) = DateValue(DateAdd('d', " & i & ", #" & Me.txtFromDate & "#)) And EmployeeID = " & Me.EmployeeID)) Then
CurrentDb.Execute "INSERT INTO tblemployee_Workpack ( EmployeeID, Role_Type, Assignment_Date, Working_Hours, Lost_Hours, Rest_Hours, Notes) " & _
"VALUES(" & Me.EmployeeID & ", " & Me.Role_Type & ", '" & strDate & "', " & _
"" & Me.Working_Hours & ", " & Me.Lost_Hours & ", " & Me.Rest_Hours & ", Nz('" & Me.Notes & "', '" & vbNullString & "'))"
'**This saves values in SignIn time/date as soon as Supervisor is assigned to a job for a specific day
CurrentDb.Execute "INSERT INTO tblEmp_Clocked_Time (EmployeeID, SignedIN) " & _
"VALUES(" & Me.EmployeeID & ", '" & strDate & "')"
End If
Next i
Attachments
Last edited: