Hi Howard
Thanks for your help
What I am actually trying to do is find out which time the client was on his
7th week, ie
ClientProgID startdate leavedate
123 10/01/03 22/01/03
123 12/03/03 26/03/03
123 11/06/03 29/08/03
324 08/08/03 14/12/03
....... ............. .............. etc etc
So: each client 'does' a random number of weeks each time they join.
What I need to do is this: Use VB code to iterate through each client record
to determine which time they hit their 7th week.
For client 123 above, (s)he only did 2 weeks, then a further 2 weeks, and so
they hit their 7th week in the 3rd time. I want to be able to return THIS
record.
(There could be as many as 8 periods of being logged as attending, but I
will only ever want to return the record where they hit their 7th week)
I am clear about the logic behind the code which I need to do, it's just I'm
no good with recordsets and navigating through them !
I need to navigate through EACH ClientProgID to return the ONE record where
they hit their 7th week (determining the 7th week is not a problem for me) -
what is a problem for me is trying to return a record for each client.
I am calling my function from a query, which passes to the function a set of
UNIQUE ClientProgID's.
The function I have written (below) is (trying to) open up the set of all
ClientProgIDs and iterate through them. I am trying to return the 7th week
date.
MY CODE:
Public Function MidpointWeek(CProgID As String) As Date
Dim break As Integer
Dim currentWeeks As Integer
Dim prevTotalWeeks As Integer
Dim totalWeeks As Integer
Dim weeksToAdd As Integer
Dim midpointDate As Date
Dim ClientProgID As Field
Dim startdate As Field
Dim leavedate As Field
Dim strSQL As String
strSQL = "SELECT * FROM [sqry_midpointFee_PSL_FEED] WHERE [ClientProgID]
= """ & CProgID & """"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
rst.MoveFirst
Set ClientProgID = rst("ClientProgID")
Set startdate = rst("startdate")
Set leavedate = rst("leavedate")
For Each ClientProgID In rst.Fields
currentWeeks = 0
prevTotalWeeks = 0
totalWeeks = 0
break = 0
Do
If leavedate.Value Is Null Then
midpointDate = DateAdd("ww", Duration, startdate.Value)
break = 1
Else
currentWeeks = DateDiff("ww", startdate.Value,
leavedate.Value)
totalWeeks = totalWeeks + currentWeeks
If totalWeeks < Duration Then
prevTotalWeeks = prevTotalWeeks + currentWeeks
rst.MoveNext
Else
weeksToAdd = Duration - prevTotalWeeks
midpointDate = DateAdd("ww", weeksToAdd,
startdate.Value)
break = 1
End If
End If
Loop Until break = 1
rst.MoveNext
Next ClientProgID
MidpointWeek = midpointDate
Thanks Howard
Jake
Howard Brody said:
What data are you looking for and what exactly are you trying to do?
It looks like you're trying to get the Start and Leave data for each
Client (?) to use them . . . somewhere else, I guess. Where is the data
stored? In your sqry_MidpointFee, is the StartDate and LeaveDate the same
for every record a Client has in the query?
Howard
----- Jake Frankham wrote: -----
FYI
I am calling my function from within a query which holds numerous CProgID's
and it is this field which is passed to function as a parameter.
strSQL = "SELECT * FROM [sqry_midpointFee] WHERE [ClientProgID] =
"""
&
CProgID & """"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
rst.MoveFirst
Set ClientProgID = rst("ClientProgID")
Set startdate = rst("startdate")
Set leavedate = rst("leavedate")
For Each ClientProgID In rst
.........................................
.........................................
Does this look right???
Cheers again
Jake
a
in
set
use