Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:47:34+00:00 2026-06-13T09:47:34+00:00

OK so I have tried a few differrent ways and searched the forums. I’ve

  • 0

OK so I have tried a few differrent ways and searched the forums. I’ve found similar problems to the one I’m having, but not quite what I’m looking for.
I have a query on my database that returns 2 columns. In the first column is a code number, and the revision for the code number in the second

e.g.

Code_1       0
Code_1       1
Code_2       0
Code_2       1
Code_2       2  

Now what I need to do is loop through this query and pick out the code and the maximum revision number associated with each code number and put these into another table so I would end up with

Code_1     1
Code_2     2

in my new table.

I’ve can’t even seem to loop through the query and all I get each time is the first result. I’ve used Debug.Print below to show myself exactly what my loop is doing.I’ve done some Java and the vba loops are obv different. One way I’ve tried is:

Dim db  As DAO.Database
Dim rs  As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Query_Name")

Dim i,j as Integer
Dim tempvar1, tempvar2 As Variant
For i = 0 To rs.EOF
tempvar1 = rs!Code_Number
For j = 0 to rs.EOF
tempvar2 = rs!Code_Rev
If Code_Rev > tempvar2 Then
tempvar2 = rs!Code_Rev
End If
Debug.Print(tempvar1 + tempvar2)
Next j
Next i

All I get is the first code number and revision on the list. If I can’t even loop through the list properly I’ve no hope of creating a new table from the results I need :-/
I’ve also tried doing something similar with a Do While Loop but same type of result.
Please show me the error of my ways in iterating through the query and please help me create a new table from the results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:47:35+00:00Added an answer on June 13, 2026 at 9:47 am

    Why not a straight query?

    SELECT tx.Code, Max(tx.[NewCode]) AS MaxOfC INTO New
    FROM tx
    GROUP BY tx.Code;
    

    Where tx is the name of your table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen a few similar posts and have tried out the answers given, but
I have tried this a few different ways but none of them seem to
I have tried this a few different ways, but the result always seems to
I have tried this a few different ways and it always seems to fail.
I have tried quite a few codes but none of them seem to work
So I am pretty new to JSP. I have tried this a few ways.
I have tried searching over the internet about this problem but not able to
I've tried asking this in a few different ways, but let's give it another
I have tried a few different ways to include the correct fonts in the
I have now tried to get this to work for a few hours but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.