+ Reply to Thread
Results 1 to 11 of 11

Data Type Mismatch in Criteria Expression

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Crewe, England
    MS-Off Ver
    Excel 2007
    Posts
    37

    Data Type Mismatch in Criteria Expression

    Hello,
    I've set up an ADODB.Connection object in a macro to retrieve information from a database. Running a simple query I have tested the code and retrieved sample information - so I know the link to the database works. However, when I try to use a date expression in my query, I get a "Data Type Mismatch in Criteria Expression" error. The query I'm using is as follows:

    Please Login or Register  to view this content.
    I'm fairly certain that it's just the syntax of the date expression but can't figure out the correct syntax. I'm referring to a database in Frontrange Goldmine which uses "Dbase IV". When I run the same query in Goldmine's SQL tool, the format for query is:

    Please Login or Register  to view this content.
    Any help with the correct syntax would be much appreciated.

    Thanks
    Williams485

  2. #2
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Data Type Mismatch in Criteria Expression

    This is sql you're creating:
    Please Login or Register  to view this content.
    If CH.ondate has Date format then there would be the type mismatch as your trying to put a string into it.
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Data Type Mismatch in Criteria Expression

    perhaps just
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Registered User
    Join Date
    08-21-2012
    Location
    Crewe, England
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Data Type Mismatch in Criteria Expression

    Thanks for your replies so far. With your combined help I've progressed with my code, but now have a different, but related issue.

    The code no longer gives me 'data type mismatch error' (please let me know if this now needs a new thread), instead the code runs but doesn't give me the expected result. I think the issue is now around the date format. My code is as follows:

    Please Login or Register  to view this content.
    The field ondate requires a US formatted date ("mm/dd/yyyy") and so i've created a couple of variables in an attempt to manage this. However, my sub now runs but doesn't pull any data out of the database (presumably because it's looking for database entries that haven't happened yet). How can I now get a date datatype in US format (while my system is in UK format)?

    thanks

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Data Type Mismatch in Criteria Expression

    probably
    Please Login or Register  to view this content.
    I wouldn't use str as a variable name because it is also a vba function name

  6. #6
    Registered User
    Join Date
    08-21-2012
    Location
    Crewe, England
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Data Type Mismatch in Criteria Expression

    Thanks JP (str tip noted). I tried using the queryDate as a string but get the mismatch error, so reverted back to a Date datatype and the sub runs again (but returns no data). I've also modified the query to include 'ondate' in the SELECT AND GROUP BY lines. This returns ondate as a date - confirmation that we're looking at a date datatype.

    Is there a way I can force the Date datatype to pass as US format to the query? Current code:

    Please Login or Register  to view this content.
    thanks.
    Last edited by williams485; 10-12-2012 at 11:53 AM.

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Data Type Mismatch in Criteria Expression

    the example that you posted initially which you said works uses a date string in single quotes. does that work in your code if you use the exact same query string?

  8. #8
    Registered User
    Join Date
    08-21-2012
    Location
    Crewe, England
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Data Type Mismatch in Criteria Expression

    No, when I run sqlQuery_3 (below) I get a data type mismatch error. This exact query, does however run directly within the CRM tool and produces results.

    Please Login or Register  to view this content.
    However, when I run query 4, I get no errors - that is the procedure executes from start to finish - but it produces no results (the same query produces results within the CRM environment). Incidentally, I've tried the date in query 4 in both mm/dd/yyyy and dd/mm/yyyy formats - to no avail.

    Please Login or Register  to view this content.
    thanks for your continued help on this one, JP.

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Data Type Mismatch in Criteria Expression

    which provider are you using in your connection?

  10. #10
    Registered User
    Join Date
    08-21-2012
    Location
    Crewe, England
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Data Type Mismatch in Criteria Expression

    As shown:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-21-2012
    Location
    Crewe, England
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Data Type Mismatch in Criteria Expression

    I've found my solution. The query string itself needs hash/pound sign enclosing the date. I also needed to convert the date to a US format to work in our database. Code:

    Please Login or Register  to view this content.
    Last edited by williams485; 10-15-2012 at 10:32 AM. Reason: Issue Resolved

+ 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