Solved Function that uses subform recordset not filtering data (1 Viewer)

mib1019

Member
Local time
Today, 06:50
Joined
Jun 19, 2020
Messages
88
Hello all,

This is probably easy, but I cannot figure it out.

I have this function in the module of a subform. The subform filters the data for a specific DetailID on the main form.
All works correctly except that it is returning 's' for all dates in the underlying table, not filtering for the handful of records showing in the subform.

Code:
Function WeeksToTextBox() As String 'returns string value of Air_Week dates in recordset, comma separated, formatted 'm/d'
    Dim v As Variant
    Dim s As String
    '
    With CurrentDb.OpenRecordset(Me.RecordSource, dbOpenSnapshot, dbReadOnly)
        If Not (.BOF And .EOF) Then
            .MoveFirst
            While Not .EOF
                v = .Fields("Air_Week").value
                If Not IsNull(v) Then
                    v = CDate(v)
                    s = s & Format(v, "m/d") & ", "
                End If
                .MoveNext
            Wend
        End If
    End With
    If Len(s) > 0 Then s = Left(s, Len(s) - 2)
    WeeksToTextBox = s
  
End Function

Thanks in advance for your help!
MIB1019
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:50
Joined
May 21, 2018
Messages
8,525
dim rs as dao.recordset
set rs = me.recordsetclone ' this would return the visible records in the subform.
with RS ....

The reason is the recordsource does not have a filter. It is simply a string representing the original source of data.
 

mib1019

Member
Local time
Today, 06:50
Joined
Jun 19, 2020
Messages
88
I figured it out! Thanks for reading....

MIB1019
 

Users who are viewing this thread

Top Bottom