The array that wouldn't

rsewell

Registered User.
Local time
Today, 17:35
Joined
Jun 4, 2003
Messages
12
Could someone please take a look at this and try to tell me why I keep getting a type mismatch error?

Code Start:
'array is created as a dynamic array, must tell it the upper bound

ReDim monthArray(ctlMonth.ItemsSelected.Count)

'need a counter to change the array element as they are populated

y = ctlMonth.ItemsSelected.Count

'need to grab the values of the multiple selections from the list box
'and populate the array
For Each varMonth In ctlMonth.ItemsSelected
monthArray(y) = ctlMonth.ItemData(varMonth)
'ERROR OCCURS ON PREVIOUS LINE

'need to decrement the array counter

y = y - 1
Next varMonth

Any help would be greatly appreciated. Thanks!:confused:
 
Looks like your passing an Long/Integer to a Varient, Try:

ReDim monthArray(ctlMonth.ItemsSelected.Count) as Long

Type Mismatch is beacuase your monthArray(y) is a Varient and ctlMonth.ItemData(varMonth) I'm guessing is a Long or Integer, possibly even a String.
 
You could also try this: (Creates an array only as big as the number of Items actually selected)

Code:
    Dim monthArray As Variant
    Dim strSelected As String
    
    'array is created as a dynamic array

    'need to grab the values of the multiple selections from the list box
    'and populate the array
    For Each varMonth In ctlMonth.ItemsSelected
        strSelected = strSelected & ctlMonth.ItemData(varMonth) & vbTab
    Next varMonth
    
    If Len(strSelected) > 1 Then
        'Strips the last Tab
        strSelected = Left(strSelected, Len(strSelected) - 1)
        monthArray = Split(strSelected, vbTab)
    End If
 

Users who are viewing this thread

Back
Top Bottom