Results 1 to 5 of 5
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Array clarification

    Code:
    Dim db As DAO.Database
    Dim rS As DAO.Recordset
    Dim CtrPlat As Integer
    Dim PlatArr As Variant
    
    Set db = CurrentDb()
    Set rS = CurrentDb.OpenRecordset("Table1")
    
    Do While Not rS.EOF
        rS.Edit
    
        If rS![Row Type] = "PLAT" Then
            CtrPlat = CtrPlat + 1
        End If
    
            ReDim PlatArr(1 To CtrPlat, 1 To 9)
    
    rS.Movenext
    Loop
    Run-time error '9': subscript out of range

    I was thinking when you redim it will get the new value. So this would get PlattArr(1 to 867, 1 to 9). If there were 867 records. I think the 1 to 9 would be referenced as the first record -

    PlatArr(CtrPlat, 1) = rS![Column 1

    PlatArr(1, Column 1) = ……..



    I think this geared more towards Excel though. so the Column 1 part could be removed. BUT with ReDim PlatArr(1 To CtrPlat) I get the same error.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Code works for me.

    Don't need to loop through recordset to get recordcount. Why don't you open recordset filtered to PLAT records?

    Set rS = CurrentDb.OpenRecordset("SELECT * FROM Table1 WHERE [Row Type]='PLAT'")
    rs.MoveLast
    ReDim PlatArr(1 To rs.RecordCount, 1 To 9)

    Or use DCount()?

    ReDim PlatArr(1 To DCount("*","Table1",[Row Type]='PLAT'), 1 To 9)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    June7,
    I have more than 1 array:

    Code:
        If rS![Row Type] = "PLAT" Then
            CtrPlat = CtrPlat + 1
        ElseIf rS![Row Type] = "FE" Then
            CtrFE = CtrFE + 1
        ElseIf rS![Row Type] = "MEQUIP" Then
            CtrMEquip = CtrMEquip + 1
        ElseIf rS![Row Type] = "DISMEQUIP" Then
            CtrDisMEquip = CtrDisMEquip = 1
        End If
        'Builds out arrays with the needed data
            ReDim PlatArr(1 To CtrPlat, 1 To 9)
            ReDim FEArr(1 To CtrFE, 1 To 9)
            ReDim MEquipArr(1 To CtrMEquip, 1 To 8)
            ReDim DEquipArr(1 To CtrDisMEquip, 1 To 9)
    I am trying to avoid using DCount as it slows down the system a lot.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Just 4 DCount() calls are noticeably slow? Looping slows performance as well. Reduce the recordset to 4 records, assuming there are only 4 types.
    Code:
    Set rS = CurrentDb.OpenRecordset("SELECT [Row Type], Count(*) AS CntType FROM Table1 GROUP BY [Row Type]")
    While Not rS.EOF
        If rS![Row Type] = "PLAT" Then
            ReDim PlatArr(1 To rS!CntType, 1 To 9)
        ElseIf rS![Row Type] = "FE" Then
            ReDim FEArr(1 To rS!CntType, 1 To 9)
        ElseIf rS![Row Type] = "MEQUIP" Then
            ReDim MEquipArr(1 To rS!CntType, 1 To 8)
        ElseIf rS![Row Type] = "DISMEQUIP" Then
            ReDim DEquipArr(1 To rS!CntType, 1 To 9)
        End If
    Wend
    Not seeing any code that populates arrays. Why do you need arrays?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Thanks June7,
    It did work and minimized some code. I have a code I am working from to use in access to use the arrays to count.

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

Similar Threads

  1. Date Criteria clarification
    By djclinton15 in forum Queries
    Replies: 26
    Last Post: 01-08-2018, 07:42 PM
  2. IsNull clarification
    By Jen0dorf in forum Access
    Replies: 6
    Last Post: 01-11-2016, 10:16 AM
  3. Clarification on distrubution
    By Jen0dorf in forum Access
    Replies: 3
    Last Post: 11-05-2015, 12:57 PM
  4. Just Looking for Clarification...
    By faythe1215 in forum Programming
    Replies: 5
    Last Post: 02-06-2015, 09:03 AM
  5. clarification with transfer commands
    By mike02 in forum Access
    Replies: 7
    Last Post: 08-08-2012, 09:37 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