Home All Groups Group Topic Archive Search About
Author
31 May 2009 4:02 AM
Webbiz
I have a recordset that I wish to cycle through until my 'cursor' is
pointing to a record with a date that is a MONDAY.

Your opinion. Would this be the way to do it?

    'Set Recordset to point to first date that is a MONDAY
    Do While Not (Weekday(Rs!Date.Value) = vbMonday Or Rs.EOF)
        Rs.MoveNext
    Loop

    If Rs.EOF then bFailed = True  'Went to end of file with no Monday
or found only at the very end. Not acceptable.

Thanks.

Webbiz

Author
31 May 2009 10:51 AM
David Youngblood
"Webbiz" <nospam@forme.thanks.com> wrote in message
news:f404251bcmcbmo5eq9ni77a750dv62ut0f@4ax.com...
>I have a recordset that I wish to cycle through until my 'cursor' is
> pointing to a record with a date that is a MONDAY.
>
> Your opinion. Would this be the way to do it?
>
>    'Set Recordset to point to first date that is a MONDAY
>    Do While Not (Weekday(Rs!Date.Value) = vbMonday Or Rs.EOF)
>        Rs.MoveNext
>    Loop

You can use Weekday in a SQL statement.
Using DAO,
    rst.FindNext "Weekday(CalDate) = 2"

Finding first Monday (one way),
    sCriteria = "SELECT CalReport.* FROM CalReport WHERE " _
             & "Weekday(CalDate) = 2 ORDER BY CalDate"

    Set rst = db.OpenRecordset(sCriteria, dbOpenDynaset)
    If rst.RecordCount Then
        Debug.Print rst.Fields("CalDate")
    End If

David
Author
31 May 2009 4:42 PM
Nobody
Show quote Hide quote
"Webbiz" <nospam@forme.thanks.com> wrote in message
news:f404251bcmcbmo5eq9ni77a750dv62ut0f@4ax.com...
>I have a recordset that I wish to cycle through until my 'cursor' is
> pointing to a record with a date that is a MONDAY.
>
> Your opinion. Would this be the way to do it?
>
>    'Set Recordset to point to first date that is a MONDAY
>    Do While Not (Weekday(Rs!Date.Value) = vbMonday Or Rs.EOF)
>        Rs.MoveNext
>    Loop
>
>    If Rs.EOF then bFailed = True  'Went to end of file with no Monday
> or found only at the very end. Not acceptable.

Have you used "ORDER BY Date"?