+ Reply to Thread
Results 1 to 5 of 5

Data Type Mismatch Error on Open Recordset

  1. #1
    Registered User
    Join Date
    02-06-2013
    Location
    Pleasant Hill, CA
    MS-Off Ver
    Excel 2007
    Posts
    23

    Data Type Mismatch Error on Open Recordset

    I am running SQL select queries against data in an Excel sheet. These queries have WHERE clauses. When I run a query with a WHERE clause on a numeric column I get a Data Type Mismatch error when the first record in the data set has a null value in the WHERE clause column.

    For example, assume the following: SELECT @ FROM [Data$] WHERE [Year] = 2015. If the first record has a blank in the Year column then Excel returns the error. If I put any number in the first record in the Year column (e.g., 0) then the query runs fine.

    Any ideas on how to avoid this error?

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: Data Type Mismatch Error on Open Recordset

    Hi masouder,

    It's been awhile since I used SQL but you could use an Immediate IF (IIF) statement to check for an empty field and return a zero if it is like so:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    02-06-2013
    Location
    Pleasant Hill, CA
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Data Type Mismatch Error on Open Recordset

    Robert,

    Thanks for the reply. Unfortunately, that did not work, nor did: IIF([Year]='',0,[Year]).


    Any other ideas?

    Michael

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Data Type Mismatch Error on Open Recordset

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    http://www.mrexcel.com/forum/excel-q...recordset.html
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    02-06-2013
    Location
    Pleasant Hill, CA
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Data Type Mismatch Error on Open Recordset

    I made the mistake of posting this to two bulletin boards (unaware that that was not cool). The other post is at:

    http://www.mrexcel.com/forum/excel-q...recordset.html

    Michael

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Type Mismatch Error in Data Entry Form
    By sj9ers in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-01-2016, 12:43 PM
  2. type mismatch Error when writing data to excel
    By svibuk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2013, 07:07 AM
  3. [SOLVED] Run-time error 13 - type mismatch when deleting data from multiple cells at once
    By missnk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2013, 08:38 PM
  4. VB run time error 13 at open type mismatch
    By sportsguy in forum Excel General
    Replies: 0
    Last Post: 04-18-2012, 10:30 AM
  5. Type Mismatch Error on Large Data Sets
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-04-2010, 04:40 PM
  6. [SOLVED] type mismatch error-copies data from one sheet to another
    By Marcotte A in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2005, 10:25 PM
  7. [SOLVED] Type Mismatch Error when getting data from another workbook
    By Tony Zappal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2005, 07:06 PM

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