Question : way to get min (or max) of field in query for report

I have a report based on a query.  If I want to add to the header a date range for the report, is there a way to get the min and max in a date field to have the report say "dd/mm/yy to dd/mm/yy"

Answer : way to get min (or max) of field in query for report

You could use the reports open event to evaluate the Min( ) and Max( ) values of a field and incorporate them into the caption of a label.  Something like:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Private Sub Report_Open(Cancel As Integer)

    Dim rs As DAO.Recordset
    Dim strSQL As String
    
    strSQL = "SELECT MIN([DateField]), MAX([DateField]) FROM "
    If InStr(Me.RecordSource, "SELECT") > 0 Then
        strSQL = strSQL & "(" & Me.RecordSource & ")"
    Else
        strSQL = strSQL & "[" & Me.RecordSource & "]"
        strSQL = Replace(Replace(strSQL, "[[", "["), "]]", "]")
    End If
        
    Set rs = CurrentDb.OpenRecordset(strSQL, , dbFailOnError)
    Me.lbl_Title.Caption = "From: " & rs(0) & " to " & rs(1)
    rs.Close
    Set rs = Nothing
    
End Sub
Random Solutions  
 
programming4us programming4us