Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513

    looping through all records is only providing values for 1st record

    the following codes 'seems' to loop through all of the records in the table, yet the debug.print shows that the values being returned are always those of the first record in the table.


    this code is in the Load event of the form; the results of the loop are assigned to values in the report header section.
    fields FxtTag and Qty are valid fields (with entries)

    Code:
     
        Dim intCnt_Comply As Integer
        Dim intCnt_NotComply As Integer
        
        intCnt_Comply = 0
        intCnt_NotComply = 0
        
        Dim rs As DAO.Recordset
        Set rs = CurrentDb.OpenRecordset("SELECT * FROM tbeFxtTagDetails")
    
        'Check to see if the recordset actually contains rows
        If Not (rs.EOF And rs.BOF) Then
            rs.MoveFirst
            Do Until rs.EOF = True  'loop through all the records in the table
                Debug.Print FxtTag & "  |  " & CStr(Qty)
                If [Efficacy] >= intNYC_MinLampEff Then
                    intCnt_Comply = intCnt_Comply + Nz(Qty, 0)
                Else
                    intCnt_NotComply = intCnt_NotComply + Nz(Qty, 0)
                End If
                rs.MoveNext
            Loop
        'Else
        '    MsgBox "There are no records in the recordset."
        End If
    
        MsgBox "Finished looping through records."
    
        rs.Close
        Set rs = Nothing
    i'm confused (seems like i've ran variations of this code a billion-zillion times; yet tonight (!?!)

    with appreciation in advance,
    m.
    Last edited by markjkubicki; 09-29-2024 at 11:28 PM. Reason: typo

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    You aren't referring to your recordset object?

    Debug.Print FxtTag & " | " & CStr(Qty)

    Should be

    Debug.Print rs!FxtTag & " | " & CStr(rs!Qty)
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    Congratulations. You are doing what another member does here, on several occasions.

    They walk a recordset but use the form controls, and wonder why the values are the same all the time.

    They have been playing with Access for over 19 years as well?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    This is why, although it's not absolutely necessary, I still always refer to a forms or reports objects with Me.
    It invokes intellisense and guarantees I know precisely what object I'm referring to.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    Quote Originally Posted by Minty View Post
    This is why, although it's not absolutely necessary, I still always refer to a forms or reports objects with Me.
    It invokes intellisense and guarantees I know precisely what object I'm referring to.
    Me.too. Pun intended.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    a mentor of mine ALWAYS used to say to me:
    "when all else fails: check the obvious !"


    much appreciation'
    m.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    Quote Originally Posted by markjkubicki View Post
    a mentor of mine ALWAYS used to say to me:
    "when all else fails: check the obvious !"


    much appreciation'
    m.
    Sometimes you cannot see the wood for the trees. :-)

    I just asked a question about a report, and I was using a form.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 06-14-2020, 01:46 PM
  2. Replies: 3
    Last Post: 03-06-2019, 11:49 AM
  3. Replies: 6
    Last Post: 01-08-2018, 12:59 AM
  4. Replies: 1
    Last Post: 07-09-2014, 10:42 AM
  5. Replies: 5
    Last Post: 10-11-2013, 07:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums