Solved

add item to array in vba

Posted on 2014-10-02
1
239 Views
Last Modified: 2014-10-02
I am looping through a recordset and where an instr is found I want to add that item to aliasarray but it wont allow, i am not sure how do deal with this as the size of the array is as of yet unknown  

I thought referencing it directly it would add the string.
Do Until RstAlias.EOF
           
            If InStr(Me.[DecodeResult].Value, .Fields("sClientDescGroup").Value) <> 0 Then
           
                AliasArray(index) = .Fields("sDesc").Value
                index = index + 1
            Else
           
           
            End If
       
       
       
        .MoveNext
        Loop
0
Comment
Question by:PeterBaileyUk
1 Comment
 
LVL 10

Accepted Solution

by:
Anthony Berenguel earned 500 total points
ID: 40357636
Try using Redim Preserve AliasArray(Index +1) as [datatype] before trying to assign a value to a position in the array.

so it would look like this
Redim Preserve AliasArray(Index +1)  as [datatype]
AliasArray(index) = .Fields("sDesc").Value
index = index + 1

Open in new window

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now