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
|