Welcome to SPN

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

Sign Up Now!
  1. Guest ji, please consider donating today!
      Become a Supporter    ::   Make a Contribution   
    Monthly Recurring Target: $300 :: Achieved: $95

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) = ...
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page