Results 1 to 4 of 4
  1. #1
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57

    Save query result into an array


    Hi

    I have this query:
    Code:
    Set rs2 = CurrentDb.OpenRecordset("SELECT userID from users where score = " & thescore)
        
        While Not rs2.EOF
        
            MsgBox (rs2!UserID)
            rs2.MoveNext
        
        Wend
    instead of having to show the values in message box, I would like to get the results saved into an array. How to do that?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Get the record count by moving last and use that to dim an array
    Then movefirst and populate that array, incrementing a counter.
    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

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Or loop over the recordset and concatenate along with a delimiter (e.g. comma) and use Split() on that string?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    In addition to the methods already mentioned you could also use a collection, or my personal favorite, a dictionary.

    What do you want to do with your data once you have it in an array?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 3
    Last Post: 02-26-2019, 07:27 PM
  2. How to export the result of save query
    By rmayur in forum Programming
    Replies: 1
    Last Post: 02-10-2015, 11:24 PM
  3. Replies: 1
    Last Post: 12-09-2012, 07:11 AM
  4. making an array out of a query result
    By Richie27 in forum Programming
    Replies: 4
    Last Post: 05-01-2012, 01:53 PM
  5. can i put the result in array?
    By dada in forum Programming
    Replies: 1
    Last Post: 08-19-2010, 07:17 PM

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