I have a public function to help determine the maximum date from 3 different values for each record. I then want to sort the form OnLoad based on that Maximum Date.
For some reason, every couple of times I open the form, instead of sorting by date, the OrderBy gets populated with a date.
When this happens I get a parameter entry. It happens to be the start_date of record 1 in the table.
Thoughts on the below code? What am I missing?
Here's what the form looks like in design view with the date populated in the orderby, somehow. Which I don't what to have happen.
For some reason, every couple of times I open the form, instead of sorting by date, the OrderBy gets populated with a date.
When this happens I get a parameter entry. It happens to be the start_date of record 1 in the table.
Thoughts on the below code? What am I missing?
Code:
Public Function MaxDate(createdDate As Variant, startDate As Variant, endDate As Variant) As Date
If IsDate(endDate) Then
MaxDate = endDate
ElseIf IsDate(startDate) Then
MaxDate = startDate
ElseIf IsDate(createdDate) Then
MaxDate = createdDate
End If
End Function
Private Sub Form_Load()
Me.OrderBy = MaxDate(Created, Start_Date, End_Date)
End Sub
Here's what the form looks like in design view with the date populated in the orderby, somehow. Which I don't what to have happen.