Thank you for looking at this. Your last comment made me re-test the code above. Evidently what was slowing it down was this:
Code:
'Clear controls
For Each Ctrl In Forms!frmExemptTimesheetRequest.Controls
If Ctrl.Name Like "txtDay*" Then
Forms!frmExemptTimesheetRequest.Controls("txtHoursDay" & Mid(Ctrl.Name, 7, Len(Ctrl.Name) - 6)).ControlSource = ""
Forms!frmExemptTimesheetRequest.Controls("txtReasonDay" & Mid(Ctrl.Name, 7, Len(Ctrl.Name) - 6)).ControlSource = ""
End If
Next Ctrl
This was clearing the ControlSource for all 84 fields. This wasn't necessary. I only need clear the ones that actually have a string in the control source. So I modified it and it runs MUCH faster.
The revised code is:
Code:
Sub UpdateExemptTimesheet()
Dim Ctrl As Control
Dim db As Database
Dim rs As DAO.Recordset
With Forms!frmExemptTimesheetRequest
'Clear the Controls
For Each Ctrl In .Controls
If Ctrl.Name Like "txtHoursDay*" Or Ctrl.Name Like "txtReasonDay*" Then
If Ctrl.ControlSource <> "" Then
Ctrl.ControlSource = ""
End If
End If
Next Ctrl
'Add any matching values
If Not IsNull(.[Request ID]) Then
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT tblExemptTimeSheetAbsences.[Time ID], tblExemptTimeSheetAbsences.[Request ID], tblExemptTimeSheetAbsences.[Date of Absence], tblExemptTimeSheetAbsences.[Hours Absent], tblExemptTimeSheetAbsences.[Reason Code] FROM tblExemptTimeSheetAbsences WHERE (tblExemptTimeSheetAbsences.[Request ID]=" & [Forms]![frmExemptTimesheetRequest]![Request ID] & ");", dbOpenDynaset)
For Each Ctrl In .Controls
If Ctrl.Name Like "txtDay*" Then
rs.FindFirst ("[Date of Absence] = #" & Ctrl.Value & "#")
If Not rs.NoMatch Then
.Controls("txtHoursDay" & Mid(Ctrl.Name, 7, Len(Ctrl.Name) - 6)).ControlSource = "=" & rs.Fields("[Hours Absent]").Value
.Controls("txtReasonDay" & Mid(Ctrl.Name, 7, Len(Ctrl.Name) - 6)).ControlSource = "=""" & rs.Fields("[Reason Code]").Value & """"
End If
End If
Next Ctrl
rs.Close
Set rs = Nothing
Set db = Nothing
End If
End With
End Sub
The attached database is the updated version.