Compile Error : Expected Array

Healey33

New Member
Joined
May 28, 2012
Messages
19
Hey, I am trying to select all of the e-mail addresses in a table and display them without duplicates. The table name is "Signed Leases", the column name is "Email" and i am trying to place it in "text4". I receive an error message "Compile Error : Expected Array" at the "emails(count) =" line. This is the code.


Rich (BB code):
Private Sub Command3_Click()
Dim db As DAO.Database
Dim strWhere As String
Dim numberOfRecords As Integer
Dim count As Integer
Dim count2 As Integer
Dim count3 As Integer
Dim label As String
Dim emails As String
emails = Array()
Dim emailsNoDuplicates As String
emailsNoDuplicates = Array()
Dim duplicate As Boolean
Dim x As Integer
x = 0
label = ""


Set db = CurrentDb ' select current database
'numberOfRecords = DCount("[ID]", "Signed Leases") 'count number of records

For count = 0 To 50 'first loop through
    strWhere = "ID = " & count + 1
    If DLookup("", "Signed Leases", strWhere) <> "" Then 'if the cell is not empty, populate the first array
        emails(count) = DLookup("[Email]", "Signed Leases", strWhere)
        duplicate = False 'reset duplicate to false
        For count2 = 0 To count - 1 'second loop for checking only previous entries
            If emails(count) = emails(count2) Then 'if the email has already been looked at, trigger duplicate to true
            duplicate = True
            End If
        Next count2
        If duplicate <> True Then 'if it is not a duplicate, populate a new array with the email
            emailsNoDuplicates(x) = emails(count2)
            x = x + 1
        End If
    End If
Next count
Text4.SetFocus
For count3 = 0 To x - 1
    label = label & emailsNoDuplicates(count3) & "; "
    Text4.Text = label
Next count3

End Sub
[/code]

I am not sure why i receive this error as the array is defined and i receive the error as it tries to populate the first array.

Thanks in advance for any help!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
When I type that in (before i try to even run it) i get an error: "Compile Error: Expected: End of Statement"
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,695
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top