Question : Changing record source for the code

Hi,

I have a code below which works fine.
It is for displaying a list of records as a note when the database is opened.
The list of records are the ones which are expiring in 3 months time from today based on a field "LA Expiry".

But the problem is that it is based on my main form's query.
But I want to base it on another query called "MQuery"
But it should open up as a pop up note only when the database is opened displaying the main form.

Please help.

Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
Private Sub Form_Load()
    Call CheckForExpiryDates
End Sub
 
Private Sub CheckForExpiryDates()
    
    Dim rs As Object
    Dim rsUnsorted As Object
 
    Dim dtExpireDateUntil As Date
    Dim strList As String
    
    Set rsUnsorted = Me.RecordsetClone
    dtExpireDateUntil = DateAdd("m", 3, Date)
    
    
        If Not rsUnsorted.EOF Then
            rsUnsorted.Sort = "[LA Expiry]"
             Set rs = rsUnsorted.OpenRecordset
             With rs
        .MoveFirst
            Do While Not .EOF
                If IsDate(.Fields("LA Expiry")) Then
                    If .Fields("LA Expiry") <= dtExpireDateUntil And .Fields("LA Expiry") >= Date Then
                        strList = strList & vbNewLine & "* " & _
                            .Fields("Site Name") & " (" & .Fields("LA Expiry") & ")"
                    End If
                End If
                .MoveNext
            Loop
        
        .Close
    End With
    End If
    
    Set rs = Nothing
    Set rsUnsorted = Nothing
    
    If strList <> "" Then
        Call MsgBox("These are the list of records that will expire in 3 months time:" _
            & vbNewLine & strList, vbInformation)
    End If
    
End Sub
Open in New Window Select All

Answer : Changing record source for the code

Sorry I mis-read your question.

You can create your Recordset from any query in your database.

For example:

Dim rstExpireIn3Mo as dao.recordset
Set rstExpireIn3Mo =CurrentDB.openrecordset("MQuery")

JeffCoachman
Random Solutions  
 
programming4us programming4us