Results 1 to 3 of 3
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,080

    Type mismatch on a "Split" statement

    I can't figure out what the issue is with a "type mismatch" with the "Split" statement below.



    Dim result as variant ' result will be assigned a cvs string from an API call
    Dim ResultArr() as variant

    ResultsArr = Split(result, ",")

    In debug, result equals the string: "12/5/14","Alerian MLP ETF","AMLP",17.97,1.13,6.23,4514800

    In the desired results of the split would be that some of the array elements would be quoted strings while others would be numbers.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    I suspect the issue is with the array declaration. For one thing, you declare ResultArr but use ResultsArr. Always include Option Explicit line in the module header and errors like that can be revealed.

    This works for me:

    Sub test()
    Dim ResultsArr As Variant, sText As String, i As Integer
    Open "C:\test.txt" For Input As #1
    Do Until EOF(1)
    Input #1, sText
    Debug.Print sText
    ResultsArr = Split(sText, ",")
    For i = 1 To UBound(ResultsArr)
    Debug.Print ResultsArr(i)
    Next
    Loop
    Close #1
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,080
    I typed in the code statements in this post rather than a copy/paste as I usually do, so the "s" issue you raised was a typo on my part. (The module does include Options Explicit)

    When I drop the parenthesis off the Dim of the array variable my code works as desired. I have no idea why Access treats things differently when the array declaration is coded ResultsArr(). Try adding the parenthesis to your test case to see if it fails.

    Dim ResultsArr As Variant

    ResultsArr = Split(result, ",")

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-05-2011, 12:05 PM
  2. Replies: 2
    Last Post: 05-17-2011, 02:40 PM
  3. "Type Mismatch" message
    By Swarland in forum Programming
    Replies: 2
    Last Post: 11-28-2010, 03:06 PM
  4. aSTR = Dir("C:\*.*") >> "Type Mismatch"
    By JGrant in forum Programming
    Replies: 1
    Last Post: 03-28-2009, 05:17 AM
  5. "Type Mismatch" Error
    By elmousa68 in forum Access
    Replies: 2
    Last Post: 12-05-2006, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums