falcondeer
Registered User.
- Local time
- Today, 08:03
- Joined
- May 12, 2013
- Messages
- 101
I am sorry to say it is not working, may be I committed a mistake some where !Code:Private Sub cmdCalcDays_Click() Dim rst As DAO.Recordset Dim iDays As Integer Dim dtStart As Date Dim dtEnd As Date dtStart = #1/1/9999# dtEnd = #12/31/1899# Set rst = Forms![tblPatient]![TblPhysiotherapy Subform].Form.RecodsetClone ' the following code will work whether the recordset is unsorted/sorted desc or asc on PT_SessionDate With rst If .RecordCount > 0 Then .MoveFirst Do Until .EOF dtStart = IIF(![PT_SessionDate] <= dtStart, ![PT_SessionDate], dtStart) dtEnd = IIF(![PT_SessionDate] >= dtEnd, ![PT_SessionDate], dtEnd) .MoveNext Loop iDays = DateDiff("d", dtStart, dtEnd) End If End With Set rst = Nothing Me![txtDays] = iDays End Sub
See the pics