Calculating Differences Between Dates in two Subforms (1 Viewer)

Pop_Access

Member
Local time
Today, 07:40
Joined
Aug 19, 2019
Messages
66
Hello,,

I have on the main form two subforms, the first one named (Referral_Date) contains one field "Referral date", while the second subform named (Visits) contains "Date of Visit" and "Days";

I need to calculate the difference between the "Referral Date" and current date on field "Days"on the second subform, but if i entered date of "Date of Visit" to freezing (Stop) the calculation.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:40
Joined
Oct 29, 2018
Messages
21,456
Hi. Welcome to AWF! Can you post a sample db?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:40
Joined
May 21, 2018
Messages
8,525
Make the control source of Days
=GetDays()
Code:
'You could do this directly in the control source, but the function is easier
Private Function GetDays() As Long
  If IsDate(Me.Date_of_Visit) And IsDate(Me.Parent.referral_date.Form.[Referral date]) Then
    GetDays = Me.Date_of_Visit - Me.Parent.referral_date.Form.[Referral date]
  End If
End Function

'I added these, but may not be necessary
Private Sub Date_of_Visit_AfterUpdate()
  Me.Recalc
End Sub

Private Sub Form_Current()
  Me.Recalc
End Sub
 

Users who are viewing this thread

Top Bottom