Results 1 to 3 of 3
  1. #1
    timesscript is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    34

    FOR...NEXT all records in a table?


    I am still trying to figure out VBA and I need help on the syntax of a statement that will loop through each record in a table and allow me to then use the values in each field of that record to perform calculations. Can someone make a basic FOR...NEXT statement to teach me how to formulate that? The help files I am reading don't seem to show me what I'm looking for.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    you dont use FOR NEXT for a table...thats what a query does, and it does it much faster.
    Use an update query to perform the calc and store in a field.

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Completely agree that an update query would be more efficient than looping. If you need it for something else, here's my template code:

    Code:
      Dim strSQL  As String
      Dim db      As DAO.Database
      Dim rs      As DAO.Recordset
    
      Set db = CurrentDb()
      
      strSQL = "SELECT ..."
      Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    
      Do While Not rs.EOF
    
        rs.MoveNext
      Loop
    
      set rs = nothing
      set db = nothing
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 17
    Last Post: 05-07-2015, 11:14 AM
  2. Replies: 9
    Last Post: 05-16-2014, 11:53 AM
  3. Replies: 2
    Last Post: 05-28-2013, 04:00 PM
  4. Replies: 1
    Last Post: 02-16-2013, 11:36 AM
  5. Replies: 2
    Last Post: 12-20-2011, 07:33 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