Dear all,
I have been provided with the following code to automatically enter the date in a field (TreatmentDate), based on two dates (StartDate and EndDate) entered in another table.
This is an example of how the result should look;
Table 1:
PatientID: 123456
StartDate: 01/01/2005
EndDate: 04/01/2005
Table 2:
Patient ID TreatmentDate
123456 01/01/2005
123456 02/01/2005
123456 03/01/2005
123456 04/01/2005
Table 1 and 2 are related through the PatientID field in a one-to-many relationship.
With the current code, I can achieve this to some extent, however, in Table 2 I get the following result in the TreatmentDate field (i.e. two instances of each date in the range);
Table 2:
Patient ID TreatmentDate
123456 01/01/2005
123456 01/01/2005
123456 02/01/2005
123456 02/01/2005
123456 03/01/2005
123465 03/01/2005
123456 04/01/2005
123456 04/01/2005
If anyone could examine the following code and suggest alterations that may fix this problem I would be extremely grateful.
Many thanks and best wishes.
Russell
(usr33t)
Public Function StartTreatment(lngVisit As Long) As Date
Dim dteStart As Date
Dim dteEnd As Date
dteStart = DLookup("[StartDate]", "tblVisit", "[VisitID] = " & lngVisit)
dteEnd = DLookup("[EndDate]", "tblVisit", "[VisitID] = " & lngVisit)
If DCount("[TreatmentID]", "tblTreatments", "[VisitID] = " & lngVisit) = 0 Then
StartTreatment = dteStart
Else
StartTreatment = DMax("[TreatmentDate]", "tblTreatments", "[VisitID] = " & lngVisit) + 1
End If
If StartTreatment > dteEnd Then
MsgBox "Visit has ended", vbOKOnly
StartTreatment = StartTreatment - 1
End If
End Function
I have been provided with the following code to automatically enter the date in a field (TreatmentDate), based on two dates (StartDate and EndDate) entered in another table.
This is an example of how the result should look;
Table 1:
PatientID: 123456
StartDate: 01/01/2005
EndDate: 04/01/2005
Table 2:
Patient ID TreatmentDate
123456 01/01/2005
123456 02/01/2005
123456 03/01/2005
123456 04/01/2005
Table 1 and 2 are related through the PatientID field in a one-to-many relationship.
With the current code, I can achieve this to some extent, however, in Table 2 I get the following result in the TreatmentDate field (i.e. two instances of each date in the range);
Table 2:
Patient ID TreatmentDate
123456 01/01/2005
123456 01/01/2005
123456 02/01/2005
123456 02/01/2005
123456 03/01/2005
123465 03/01/2005
123456 04/01/2005
123456 04/01/2005
If anyone could examine the following code and suggest alterations that may fix this problem I would be extremely grateful.
Many thanks and best wishes.
Russell
(usr33t)
Public Function StartTreatment(lngVisit As Long) As Date
Dim dteStart As Date
Dim dteEnd As Date
dteStart = DLookup("[StartDate]", "tblVisit", "[VisitID] = " & lngVisit)
dteEnd = DLookup("[EndDate]", "tblVisit", "[VisitID] = " & lngVisit)
If DCount("[TreatmentID]", "tblTreatments", "[VisitID] = " & lngVisit) = 0 Then
StartTreatment = dteStart
Else
StartTreatment = DMax("[TreatmentDate]", "tblTreatments", "[VisitID] = " & lngVisit) + 1
End If
If StartTreatment > dteEnd Then
MsgBox "Visit has ended", vbOKOnly
StartTreatment = StartTreatment - 1
End If
End Function