?
Solved

remove array element in access vba

Posted on 2014-10-02
5
Medium Priority
?
1,954 Views
Last Modified: 2014-10-03
I wish to remove an element from the array that contains " " or "" I know it will involve a redim maybe a preserve too but not sure how to remove at the right place

so far:

  For index = LBound(AliasArray) To UBound(AliasArray)
            If AliasArray(index) = " " Or AliasArray(index) = "" Then remove that element
           
       
        Next index
0
Comment
Question by:PeterBaileyUk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:James Elliott
ID: 40358800
You can use a temporary array.

Option Explicit

Sub EE()

Dim arr As Variant
Dim arrTmp() As Variant
Dim x As Long, counter As Long

arr = Array(1, 2, 3, " ", 4)

For x = LBound(arr) To UBound(arr)

    If Not (arr(x) = "" Or arr(x) = " ") Then
    
        ReDim Preserve arrTmp(counter)
        
        arrTmp(counter) = arr(x)
        
        counter = counter + 1
        
    End If
Next x

arr = arrTmp

End Sub

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 40358804
that looks great could you teach me about this part :

arr = Array(1, 2, 3, " ", 4)

i can see its making arr equal to array but the bits within the brackets i am not sure about
0
 
LVL 12

Accepted Solution

by:
James Elliott earned 2000 total points
ID: 40358807
Sorry, that is just me creating the initial array with some elements to test. If your AliasArray already has elements then you can remove the line. Something like this.

Option Explicit


Dim arrTmp() As Variant
Dim x As Long, counter As Long



For x = LBound(AliasArray) To UBound(AliasArray)

    If Not (AliasArray(x) = "" Or AliasArray(x) = " ") Then
    
        ReDim Preserve arrTmp(counter)
        
        arrTmp(counter) = AliasArray(x)
        
        counter = counter + 1
        
    End If
Next x

AliasArray= arrTmp

Open in new window

0
 
LVL 34

Expert Comment

by:Norie
ID: 40358826
How are you creating the array in the first place?

If it's through code using Redim etc then perhaps you could add something to the code that creates the array to exclude the values/strings/whatever you don't want in the array.
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 40358827
brilliant had to ask or i wont learn
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…
Suggested Courses

770 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