Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Do While ignores .eof

Discussion in 'Information Technology' started by marc_donofrio@yahoo.com, Jul 28, 2006.

Tags:
  1. marc_donofrio@yahoo.com

    marc_donofrio@yahoo.com
    Expand Collapse
    Guest

    Hi

    I am trying to get a do while loop to enter data in the relevant txt
    boxes - if there are two bookings on a day then to put the details in
    one text box - then move on to the next box, fill in the detaisl for
    that day etc.

    The problem is that when the rs hits end of file it crashes instead of
    exiting this code and moving on to the next.

    I hope some one can see where i am going wrong.

    If Not rsBooking.EOF = True Then

    For DayNum = 1 To 7

    If rsBooking!Date = (ReneDate + (DayNum - 1)) Then

    Do While rsBooking!Date = (ReneDate + (DayNum - 1)) And Not
    rsBooking.EOF

    Forms![Calendar]("txtRow" & RowNum & DayNum) =
    Forms![Calendar]("txtRow" & RowNum & DayNum) &
    Left(rsBooking![StartTime], 5) & "-" & Left(rsBooking![EndTime], 5) &
    vbCrLf & rsBooking![EventTitle] & vbCrLf
    Forms![Calendar]("txtRow" & RowNum & DayNum & "ID") =
    rsBooking![RoomID]
    Forms![Calendar]("txtRow" & RowNum & DayNum & "D") = rsBooking![Date]
    rsBooking.MoveNext
    Loop

    End If

    If rsBooking.EOF = True Then
    Exit For
    End If

    Next DayNum
    End If
     
  2. Loading...

    Similar Threads Forum Date
    Arts/Society I Refuse To Be Silent While You’re Being Attacked, Vilified And Threatened Language, Arts & Culture Oct 9, 2016
    Sikh News Sikhs Face Problems While Carrying Kirpans In Khyber-Pakhtunkhwa - SikhSiyasat.Net Breaking News Jul 29, 2016
    While Children Are Like Dogs — Teenagers Are Like Cats Parenting Jul 9, 2016
    Listening to Gurbani while driving?? Sikh Rehat Maryada Jan 13, 2016
    Conentrating while Doing Paath? Blogs Oct 22, 2015

  3. Michael J. Strickland

    Michael J. Strickland
    Expand Collapse
    Guest

    <marc_donofrio@yahoo.com> wrote in message
    news:1149088268.263090.49320@i40g2000cwc.googlegroups.com...
    > Hi
    >
    > I am trying to get a do while loop to enter data in the relevant txt
    > boxes - if there are two bookings on a day then to put the details in
    > one text box - then move on to the next box, fill in the detaisl for
    > that day etc.
    >
    > The problem is that when the rs hits end of file it crashes instead of
    > exiting this code and moving on to the next.
    >
    > I hope some one can see where i am going wrong.
    >
    > If Not rsBooking.EOF = True Then
    >
    > For DayNum = 1 To 7
    >
    > If rsBooking!Date = (ReneDate + (DayNum - 1)) Then
    >
    > Do While rsBooking!Date = (ReneDate + (DayNum - 1)) And Not
    > rsBooking.EOF
    >
    > Forms![Calendar]("txtRow" & RowNum & DayNum) =
    > Forms![Calendar]("txtRow" & RowNum & DayNum) &
    > Left(rsBooking![StartTime], 5) & "-" & Left(rsBooking![EndTime], 5) &
    > vbCrLf & rsBooking![EventTitle] & vbCrLf
    > Forms![Calendar]("txtRow" & RowNum & DayNum & "ID") =
    > rsBooking![RoomID]
    > Forms![Calendar]("txtRow" & RowNum & DayNum & "D") = rsBooking![Date]
    > rsBooking.MoveNext
    > Loop
    >
    > End If
    >
    > If rsBooking.EOF = True Then
    > Exit For
    > End If
    >
    > Next DayNum
    > End If
    >



    This might be because your "Do While" test accesses a record
    (rsBooking!Date) when you could potentially be at the end of file.
    I believe VBA tests the first condition first so when you are at EOF, it
    tries to access a record (rsBooking!Date) for the first test before it
    notices that there is no current record (it is at EOF).

    Try putting the first condition in an If/Then block and make the main loop
    test for EOF only.

    While Not rsBooking.EOF
    If rsBooking!Date = ReneDate + (DayNum - 1) Then
    Forms![Calendar]("txtRow" & RowNum & DayNum) = ...
     

Share This Page