Welcome to SPN

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

Sign Up Now!

Recordset Loop Unexpected Behaviour

Discussion in 'Information Technology' started by Simon Harris, Jul 28, 2006.

  1. Simon Harris

    Simon Harris
    Expand Collapse
    Guest

    Hi All,

    The following code is only showing me one message box with one idInvoice.
    Yet the SQL behind it returns 4 distinct rows, each with a different
    idInvoice.

    Set conn = CurrentDb
    Set RSCheckCurrentReadings = conn.OpenRecordset(strSQL)
    Do While Not RSCheckCurrentReadings.EOF
    MsgBox (CInt(RSCheckCurrentReadings("idInvoice")))
    RSCheckCurrentReadings.MoveNext
    Loop

    Any ideas will be much appreciated!

    Thanks!
    Simon.

    --
    -
    * Please reply to group for the benefit of all
    * Found the answer to your own question? Post it!
    * Get a useful reply to one of your posts?...post an answer to another one
    * Search first, post later : http://www.google.co.uk/groups
    * Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
     
  2. Loading...

    Similar Threads Forum Date
    Opinion National Talent Search Examination: Bloopers in Talent Search Test Punjab, Punjabi, Punjabiyat Jul 2, 2009
    Sikh News Punjab to plug loopholes in evasion of road, entry taxes (New Kerala) Breaking News Jul 12, 2007

  3. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On Mon, 19 Jun 2006 21:13:03 +0100, "Simon Harris"
    <too-much-spam@makes-you-fat.com> wrote:

    >Hi All,
    >
    >The following code is only showing me one message box with one idInvoice.
    >Yet the SQL behind it returns 4 distinct rows, each with a different
    >idInvoice.
    >
    >Set conn = CurrentDb
    >Set RSCheckCurrentReadings = conn.OpenRecordset(strSQL)
    >Do While Not RSCheckCurrentReadings.EOF
    > MsgBox (CInt(RSCheckCurrentReadings("idInvoice")))
    > RSCheckCurrentReadings.MoveNext
    >Loop
    >
    >Any ideas will be much appreciated!
    >
    >Thanks!
    >Simon.


    It may be helpful to put a line

    RSCheckCurrentReadings.MoveFirst

    before the DO WHILE loop.

    John W. Vinson[MVP]
     
  4. Graham Mandeno

    Graham Mandeno
    Expand Collapse
    Guest

    Hi Simon

    No idea. But have you declared your object variables correctly?

    Dim conn as DAO.Database
    Dim RSCheckCurrentReadings as DAO.Recordset

    I'm suspicious that your variable name "conn" suggests an ADODB.Connection,
    while it should be a DAO.Database.

    Also, have you tried?
    RSCheckCurrentReadings.MoveLast
    MsgBox RSCheckCurrentReadings.RecordCount

    Of course, this should give 4.

    If you're still in trouble, post some more code including variable
    declarations and the value of strSQL.
    --
    Good Luck!

    Graham Mandeno [Access MVP]
    Auckland, New Zealand

    "Simon Harris" <too-much-spam@makes-you-fat.com> wrote in message
    news:u74RFz9kGHA.4888@TK2MSFTNGP02.phx.gbl...
    > Hi All,
    >
    > The following code is only showing me one message box with one idInvoice.
    > Yet the SQL behind it returns 4 distinct rows, each with a different
    > idInvoice.
    >
    > Set conn = CurrentDb
    > Set RSCheckCurrentReadings = conn.OpenRecordset(strSQL)
    > Do While Not RSCheckCurrentReadings.EOF
    > MsgBox (CInt(RSCheckCurrentReadings("idInvoice")))
    > RSCheckCurrentReadings.MoveNext
    > Loop
    >
    > Any ideas will be much appreciated!
    >
    > Thanks!
    > Simon.
    >
    > --
    > -
    > * Please reply to group for the benefit of all
    > * Found the answer to your own question? Post it!
    > * Get a useful reply to one of your posts?...post an answer to another one
    > * Search first, post later : http://www.google.co.uk/groups
    > * Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
    >
     

Share This Page