Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Coding a Loop?

Status
Not open for further replies.

david6633

Programmer
Jul 28, 2003
39
GB
I cannot quite get my head around this problem so any help would be appreciated.

I have created an array from a recordset - the data in which is ok and looks like this:

Date Value
14/01/1998 4
28/11/1991 4
04/02/1982 2
30/10/1980 1
12/03/1975 1

What I want to do is pick up the date of the latest change of the value, in this example it would be 28/11/1991, but if there was no change in the value pick up the earliest date in the list (12/03/1975).

I am guessing that it will be a loop but not sure how to code it.

David
Remember: You only know what you know
and - you don't know what you don't know!
 
How are ya david6633 . . .

I don't know if your using a single array, two arrays or a two demensional array. The following is an example of what you require using two arrays:

Code:
Public Function SpecDate() As Date
   'Your code to setup Array/s
   '
   '
   'Dates are in aryDate
   'Numbers are in aryNum
   
   For n = UBound(aryNum) To LBound(aryNum) + 1
      If aryNum(n) <> aryNum(n - 1) Then
         SpecDate = aryDate(n)
         Exit For
      ElseIf n = LBound(aryNum) + 1 Then
         SpecDate = aryDate(n - 1)
      End If
   Next

End Function

The code can be easily modified to suite your needs, no matter dimensional specifics.

Let me know if you have questions . . . . .


TheAceMan [wiggle]

 
How do you get your recordset?
If by a query, why not sort by date DESC?
Then when you open the recordset, the first record you read will ALWAYS be the one you want.

 
How are JeffTullin . . . .

You must have speed read the post origination.

david6633 said: What I want to do is pick up the date of the latest change of the value, in this example it would be 28/11/1991, but if there was no change in the value pick up the earliest date in the list (12/03/1975).


TheAceMan [wiggle]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top