Results 1 to 5 of 5
  1. #1
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159

    making an array out of a query result

    Posting a lot here as I am a total noob and have no place else to go!!



    making an array out of a query result - how do I do this??? Help!


  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Pretty vague question. What are you trying to do? Maybe a recordset would be better. Why do you want to use an array?

  3. #3
    Richie27 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    159
    I know ya and apologies.

    Well say I want to - "select * fruits from fruit_n_veg_shop" and I want to make an array directly out of that.

    It could have any number of records an maybe like ("apples","oranges","pears","peachs", etc etc)

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Again, Why do you want to use an array? Would a recordset work? Arrays generally take more coding....

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK, so here is an example of using a dynamic array.

    Code:
    Public Sub MakeArray()
    'uses DAO
       Dim dbs As DAO.Database
       Dim rst As DAO.Recordset
    
       Dim varArray() As String  'dynamic array name
       Dim k As Integer   'counter
       Dim RC As Integer  'record count
    
       Set dbs = CurrentDb()
       k = 0
       'open recordset
       'SQL of query = "SELECT DISTINCT fruit_n_veg_shop.Fruits FROM fruit_n_veg_shop;"
       'NOTE:  query has only one field
       
       Set rst = dbs.OpenRecordset("qryFruits", dbOpenDynaset)
       
       If Not (rst.BOF And rst.EOF) Then
          rst.MoveLast
          RC = rst.RecordCount
          rst.MoveFirst
          
          'set array dimension
          ReDim varArray(RC)
    
          'fill recordset
          Do Until rst.EOF
             varArray(k) = rst.Fields(0)
             rst.MoveNext
             k = k + 1
          Loop
       End If
       '--------------------------------------
    
       '    do other stuff here with the array
    
       '--------------------------------------
    
       rst.Close
       Set rst = Nothing
       Set dbs = Nothing
    End Sub

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

Similar Threads

  1. VB ADO Query Result Set
    By Bedsingar in forum Access
    Replies: 5
    Last Post: 09-05-2011, 10:45 AM
  2. making a query
    By macattack03 in forum Access
    Replies: 2
    Last Post: 04-23-2011, 12:00 PM
  3. can i put the result in array?
    By dada in forum Programming
    Replies: 1
    Last Post: 08-19-2010, 07:17 PM
  4. How do I determine a SQL query result?
    By Trainman in forum Database Design
    Replies: 1
    Last Post: 10-15-2009, 04:49 AM
  5. Result of Count Query not known elsewhere
    By Carole in forum Access
    Replies: 1
    Last Post: 09-07-2008, 09:39 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