Public Function LastPaymentDate( Conn As ADODB.Connection, _
AccountNumber As String) As Date
Dim RS As ADODB.Recordset

Set RS = Conn.Execute( _
"SELECT * " _
& "FROM AR " _
& "WHERE AccountNumber = '" & AccountNumber & "' " _
& "ORDER BY PostingDate DESC")
LastPaymentDate = IIf(RS.EOF, 0, RS("PostingDate"))
RS.Close
Set RS = Nothing
End Function