avincent61
New member
- Local time
- Today, 07:15
- Joined
- Mar 7, 2022
- Messages
- 20
Hello! Looking for help so I can stop banging my head into the wall...
My newest headache: I'm using a subform to mass schedule appointments at 10 minute intervals. The loop function I have works for applying dates to records the user selects in the subform (continuous), so I used the same loop code with changes for the times, but I can't seem to get it right.
In my attempts I made an independent table tblApptTimes with the TimeSlots and TimeDesc, which works until I use DayShift (TimeDesc) as the criteria in the DMax function. DayShift is a short text field is adjacent to the TimeSlot used to kick off the 10 minute intervals. I think the issue is that tblApptTimes is not in the Main form or the subform, but I honestly don't know.
Ultimate Goal: User selects multiple records (in a row) displayed on subform (record selectors), User clicks a cmd button (Day 1 Times/Day 2 Times), and the appt times for those records are updated at 10 minute intervals (7:10, 7:20, 7:30, etc.). The start time is held in tblApptTimes (7:00). The screenshot shows how the form is oriented, though it's not finished.
ApptTime and TimeSlot are Date/Time fields set to MediumTime
My code is below, which is in a separate module. Some of my attempts (RS.Fields) are commented out to show trial/error. The most recent code give Run-Time Error 2471 referencing 'DayShift'.
My newest headache: I'm using a subform to mass schedule appointments at 10 minute intervals. The loop function I have works for applying dates to records the user selects in the subform (continuous), so I used the same loop code with changes for the times, but I can't seem to get it right.
In my attempts I made an independent table tblApptTimes with the TimeSlots and TimeDesc, which works until I use DayShift (TimeDesc) as the criteria in the DMax function. DayShift is a short text field is adjacent to the TimeSlot used to kick off the 10 minute intervals. I think the issue is that tblApptTimes is not in the Main form or the subform, but I honestly don't know.
Ultimate Goal: User selects multiple records (in a row) displayed on subform (record selectors), User clicks a cmd button (Day 1 Times/Day 2 Times), and the appt times for those records are updated at 10 minute intervals (7:10, 7:20, 7:30, etc.). The start time is held in tblApptTimes (7:00). The screenshot shows how the form is oriented, though it's not finished.
ApptTime and TimeSlot are Date/Time fields set to MediumTime
My code is below, which is in a separate module. Some of my attempts (RS.Fields) are commented out to show trial/error. The most recent code give Run-Time Error 2471 referencing 'DayShift'.
Code:
Function SetTimesDay1()
Dim i As Long
Dim F As Form
Dim RS As Recordset
Dim formRecords As DAO.Recordset
' Get the form and its recordset.
Set F = Forms![frmEyeExams]![sfrmEyeApptCards].[Form]
Set RS = F.RecordsetClone
' Move to the first record in the recordset.
RS.MoveFirst
' Move to the first selected record.
RS.Move F.SelTop - 1
' Enumerate the list of selected records
For i = 1 To F.SelHeight
RS.Edit
RS.Fields("ApptTime") = DateAdd("n", 10, DMax("TimeSlot", "tblApptTimes") + 1)
' ' RS.Fields("ApptTime") = DateAdd("n", 10, DMax("TimeSlot", "tblApptTimes", "[TimeDesc]" = "DayShift") + 1)
' ' RS.Fields("ApptTime") = DateAdd("n", 10, (DMax("TimeSlot", "tblApptTimes", "[TimeDesc]='" & "DayShift" & "'") + 1))
' ' RS.Fields("ApptTime") = DateAdd("n", 10, Forms![frmEyeExams]![sfrmEyeApptCards].[Form].txtApptTime)
RS.Update
RS.MoveNext
Next i
End Function