+ Reply to Thread
Results 1 to 4 of 4

ODBC SQL string - type mismatch

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    Los Angeles, CA USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    ODBC SQL string - type mismatch

    So I am creating a macro that reads anything from cell A4 until there is a blank row.

    I concatenate every string column A that has data and turn it into a string. Then I inserted the string into the sql select statement and it works when I have like 6 cells selected. When I select all the cells I need then it crashes and give me the error message 'Run time error "13" type mismatch"

    This is a small sample of cells, but at this point the macro is already crashing.
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    '12345678'
    ''
    '12345678'


    Thank you in advance for all your help!!!


    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: ODBC SQL string - type mismatch

    What exactly is in the variable s when the code fails?

    Do the cells actually have a leading and trailing single quote?

    If they do then you might be losing the leading quote which would make what's in s incorrect.

    Try adding the single quote.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-01-2012
    Location
    Los Angeles, CA USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: ODBC SQL string - type mismatch

    Variable s contains order numbers like these:
    12345678
    12345678

    Variable S puts them into comma delimited and I added the single quotes in excel. I am not sure what the problem was, but I used this to fix it : http://www.mrexcel.com/forum/excel-q...lications.html

    The fix was to turn the commandtext array into a string and then call the string. Please see code for reference:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: ODBC SQL string - type mismatch

    Ah, that old thread.

    Should have suggested using a string, it's what I do.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1