Ok, I finally figured out what I was doing wrong. Of course, it was an error on my part. I was placing the UNION SELECT statement in the wrong section of the code, so it was only being read before the loop, not during the loop. I also realized I could remove all the references to "qryAppointmentPatient" since that was the only query I was pulling records from.
Here is the working version (for those of you who might benefit from my mistake):
Sub PopulateCalendar()
' Dim variables
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim boxday As Variant
Dim i As Integer
Dim fEmpty As Boolean
Dim thatQry As String
Dim strRowSource As String
' Assign variables
Set db = CurrentDb
Set rs = db.OpenRecordset("qryAppointmentPatient")
' Date handler
boxday = DateSerial(Year(Me![FirstDate]), Month(Me![FirstDate]), 1) ' first day of month
boxday = DateAdd("d", 1 - Weekday(boxday), boxday) ' back to sunday
' need to loop thru 42 textboxes
For i = 0 To 41
Me("box" & i).ColumnCount = 3
Me("box" & i).ColumnWidths = ".6 in;.120 in;"
fEmpty = (rs.BOF And rs.EOF)
If fEmpty Then
strRowSource = Mid(Nz("", "1234567 "), 8)
Else
thatQry = " UNION SELECT Lname, Fname, " & Chr(34) & "R" & Chr(34) & " FROM qryAppointmentPatient WHERE (((Recert)= #" & Format(boxday, "mm/dd/yyyy") & "#));"
strRowSource = "SELECT Lname, Fname, " & Chr(34) & "SV" & Chr(34) & " FROM qryAppointmentPatient WHERE (((SVA)= #" & Format(boxday, "mm/dd/yyyy") & "#) OR ((SVB)= #" & Format(boxday, "mm/dd/yyyy") & "#) OR ((SVC)= #" & Format(boxday, "mm/dd/yyyy") & "#) OR ((SVD)= #" & Format(boxday, "mm/dd/yyyy") & "#) OR ((SVE)= #" & Format(boxday, "mm/dd/yyyy") & "#))" & thatQry
End If
Me("box" & i).RowSource = strRowSource
Me("box" & i).Visible = False
If Month(boxday) = Month(Me!FirstDate) Then Me("box" & i).Visible = True
boxday = boxday + 1 ' nextday
Next i
End Sub
Bookmarks