Results 1 to 2 of 2
  1. #1
    system243trd is offline Novice
    Windows 2K Access 2003
    Join Date
    Nov 2011
    Posts
    27

    SQL Containing REDIM function and a loop

    I am looking at one of our legacy systems which contains some code similar to the code below.
    I understand that it is opening a connection and selecting values from tabla. Then it checks if the total rows are greater than 0.

    Please can someone tell me what ReDim function is doing, this will then give me a better understanding of how the For loop is working.


    Dim abc as string
    Dim a1 as integer
    Dim a2 as integer
    Dim rtotal as integer
    Dim anrecord as new adodb.recordset
    Dim sqla as string

    sqla = select avalue, bvalue from tablea
    anrecord.open.sqltext, currentproject,connection, asOpenKeyset, adLockOptimistic


    rtotal = anrecord.recordcount

    If rtotal > 0 then
    ReDim abc(rtotal,2)
    anrecord.movefirst
    For a1 =1 to rtotal
    abc(a1, 1) = anrecord.avalue
    abc(a1, 2) = anrecord.bvalue
    Next
    anrecord.close

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    It is resizing or re-dimensioning the string that was previously declared as a string to a multidimensional Array of String. It is using the recordcount for the first dimension and hardcoding the second dimension as 2 elements.

    Then it is looping through the recordset to populate assign values to the elements dimensioned.

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

Similar Threads

  1. Replies: 12
    Last Post: 06-05-2015, 04:27 PM
  2. Replies: 6
    Last Post: 11-05-2014, 05:27 PM
  3. Loop function not moving to next record
    By jax1000rr in forum Programming
    Replies: 3
    Last Post: 02-26-2013, 12:21 PM
  4. Error loop when I misscode in a function?
    By stumped in forum Programming
    Replies: 5
    Last Post: 09-27-2012, 01:25 AM
  5. Array will not ReDim...
    By yeah in forum Programming
    Replies: 1
    Last Post: 10-08-2011, 06:30 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