Variant Array Split() Syntax (1 Viewer)

cheuschober

Muse of Fire
Local time
Today, 01:47
Joined
Oct 25, 2004
Messages
168
Hey there folks. Run into a pickle that I just can't seem to find documented in what I have available to me (which is mostly O'Reilly or MsVBA Help).

Does anyone know the proper syntax for getting a comma-delimited text field (pulled via recordset) into a dynamic variant array using split()? I've tried quite a few combos to create it but no luck thus far (continue receiving a 'type mismatch' error).

Code is as follows (lets assume I know how to open a recordset and use it properly -- recordset does retrieve the value of the requested text field with no hangups):
Code:
Dim varSendTo() as Variant
Dim strSendTo as String

'Creates a string SendTo just to be redundant (shouldn't need this)
strSendTo = rs!SendTo

'Splits "To" Array
varSendTo = Split(strSendTo, ",", -1)

Could it be that I'm missing some reference ? I've tried various combinations of varSendTo and varSendTo(), strSendTo and rs!SendTo among others with little luck in dealing with this mismatch.

Any thoughts? Access 2k here with Jet 8 and the most recent SP so I'm reasonably sure split should be supported.

Many thanks,
~Chad
 

pono1

Registered User.
Local time
Yesterday, 22:47
Joined
Jun 23, 2002
Messages
1,186
Chad,

Something to try...

Code:
Dim varSendTo() as String 'changed to string
Dim strSendTo as String
Dim i as long

'Creates a string SendTo just to be redundant (shouldn't need this)
strSendTo = rs!SendTo

'Test
    debug.print strSendTo

'Splits "To" Array
varSendTo = Split(strSendTo, ",")

'Check it
    For i = LBound(varSendTo) To UBound(varSendTo)
        Debug.Print varSendTo(i)
    Next i

Regards,
Tim
 
Last edited:

cheuschober

Muse of Fire
Local time
Today, 01:47
Joined
Oct 25, 2004
Messages
168
Many thanks, Tim...

I actually left out one combination that works (though you wouldn't think it would). The VBA Help File states that you have to pass the results of Split() to a dynamic array (I needed a variant array for my purposes). Hence why I thought:

Code:
Dim varSendTo() as Variant

In actuality, it seems, the Split() function changes the variable it passes its result to into an array as a part of the function so the correct syntax would be...
Code:
Dim varSendTo as Variant
varSendTo = Split(rs!SendTo,",",-1)

This gives me the resultant variant array I need.

Regards,
~Chad
 

Users who are viewing this thread

Top Bottom