For the past year+, a form I created has worked flawlessly on all PC's my front end is distributed to.
As of today, some PCs are getting a type mismatch (error 13) when I try to set a variable to the return from a DAO recordset.
I checked the windows update history of one of these, and it hasn't had any updates in the past 2 weeks. This function was confirmed working yesterday.
As far as I know I'm only using DAO objects, so the microsoft help doc that says to explicitly define ADODB and DAO variables shouldn't apply, right?
Access will also crash completely if I try to do a watch on the recordset.
Here is the subroutine, the line it fails on has a comment:
Code:
Private Sub Employee_List_AfterUpdate()
'Pull the new employee ID:
Employee_ID_Temp = Me.Employee_List.Value
'Pull the employee's name as a string:
Dim strSQL As String
Dim strFirstName As String
Dim strLastName As String
Dim rst As DAO.Recordset
Dim Total_Vacation_Days As Integer
Dim Vacation_Days_Used As Integer
strSQL = "SELECT Employees.First_Name, Employees.Last_Name FROM Employees WHERE (((Employees.ID)=" & Employee_ID_Temp & "));"
Set rst = CurrentDb.OpenRecordset(strSQL)
If IsNull(rst.Fields("First_Name").Value) = False Then
strFirstName = rst!First_Name
ElseIf IsNull(rst.Fields("First_Name").Value) = True Then
strFirstName = " "
End If
If IsNull(rst.Fields("Last_Name").Value) = False Then
strLastName = rst!Last_Name
ElseIf IsNull(rst.Fields("Last_Name").Value) = True Then
strLastName = " "
End If
Employee_Name = (strFirstName & " " & strLastName)
'Set the textbox equal to the employee's name string:
Me.Current_Employee_Text.Value = Employee_Name
Me.txtEmployeeID.Value = Employee_ID_Temp
'Update vacation days textbox:
strSQL = "SELECT Vacation_Master.Total_Vacation_Days FROM Vacation_Master WHERE (((Vacation_Master.Calendar_Year)= Year(Date())) AND ((Vacation_Master.Employee_ID)=" & Employee_ID_Temp & "));"
Set rst = CurrentDb.OpenRecordset(strSQL)
If rst.EOF = False Then
Total_Vacation_Days = rst!Total_Vacation_Days 'this is the line it fails on
ElseIf rst.EOF = True Then
Total_Vacation_Days = 0
End If
Me.txtEmployee_Vacation_Days.Value = Total_Vacation_Days
strSQL = "SELECT Sum(Vacation_Time.Vacation_Days_Used) AS SumOfVacation_Days_Used FROM Vacation_Time GROUP BY Vacation_Time.Employee_ID, Year([Start_Date]) HAVING (((Vacation_Time.Employee_ID)=" & Employee_ID_Temp & ") AND ((Year([Start_Date]))=Year(Date())));"
Set rst = CurrentDb.OpenRecordset(strSQL)
If rst.EOF = False Then
Vacation_Days_Used = rst!SumOfVacation_Days_Used
ElseIf rst.EOF = True Then
Vacation_Days_Used = 0
End If
Me.txtVacationDaysRemaining = (Total_Vacation_Days - Vacation_Days_Used)
'requery by updating the table recordset:
subformSQL = "SELECT TimeClock.Employee_ID, TimeClock.Clock_Date, TimeClock.Time_In, TimeClock.Lunch_Out, TimeClock.Lunch_In, TimeClock.Time_Out, (Abs(DateDiff(""n"",[Timeclock].[Time_In],[Timeclock].[Lunch_Out]))+Abs(DateDiff(""n"",[Timeclock].[Lunch_In],[Timeclock].[Time_Out])))/60 AS Hours_Worked, TimeClock.Notes FROM TimeClock WHERE (((TimeClock.Employee_ID)=" & Employee_ID_Temp & ") AND ((TimeClock.Clock_Date) Between [Forms]![TimeClock_Form]![weekList] And ([Forms]![TimeClock_Form]![weekList]-Weekday([Forms]![TimeClock_Form]![weekList])+8))) ORDER BY TimeClock.Clock_Date DESC;"
'MsgBox ([Forms]![TimeClock_Form]![weekList])
Me.Employee_TimeClock_Query_subform.Form.RecordSource = subformSQL
'Update the graph to show current employee:
strSQL = "SELECT (Abs(DateDiff(""n"",[Timeclock].[Time_In],[Timeclock].[Lunch_Out]))+Abs(DateDiff(""n"",[Timeclock].[Lunch_In],[Timeclock].[Time_Out])))/60 AS Hours_Worked, TimeClock.Clock_Date, TimeClock.Employee_ID, Employees.First_Name, Employees.Last_Name FROM Employees INNER JOIN TimeClock ON Employees.ID = TimeClock.Employee_ID WHERE (((TimeClock.Employee_ID)=" & Employee_ID_Temp & ")) AND ([Timeclock.Clock_Date] Between [Forms]![TimeClock_Form]![weekList] And ([Forms]![TimeClock_Form]![weekList]-Weekday([Forms]![TimeClock_Form]![weekList])+8));"
CurrentDb.QueryDefs("Employee_Hours_Worked").SQL = strSQL
Me.Employee_Hours_Chart.RowSource = "Employee_Hours_Worked"
Me!Employee_Hours_Chart.Requery
Me!weekList.Requery
End Sub
I have this issue on my home PC, but not on my work PC. So I have a test environment for both working and not.