Results 1 to 4 of 4
  1. #1
    AndyDandy is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Mar 2018
    Posts
    7

    Data mismatch error result in query

    Hello,
    Searching did not yield a prior forum posting so here is my dilema working with an Access query.

    Filtering field: SURVCATEGORY (text field): the field could have a combination of letters or numbers (IA2, 2AI, I2, E1, ABCDE, ...)
    Filter: Like "*I*" Or Like "*E*" Or Like "*1*" Or Like "*2*" And Not Like "*D*"
    This filter is successful in extracting the data set desired.

    I now wanted to identify the record with a calculated column that if the condition was met, the value of the exit date would display, otherwise "No" so I added LicYes: LicYes: IIf([survcateg] Like "*I*",[Exit_Date],IIf([survcateg] Like "*E*",[Exit_Date],"No"))
    Comment: this results in a data type mismatch.

    1. If I take Or Like "*1*" Or Like "*2*" out of my SURVCATEGORY filter LicYes works fine and there are no errors. Obviously it is not liking the numerals in this calculation.
    2. I have tried using cstr() without success: LicYes: IIf(cstr([survcateg]) Like "*I*",[Exit_Date],IIf(cstr([survcateg]) Like "*E*",[Exit_Date],"No"))
    3. I have tried using a calculated string of the SURVCATEGORY called STRCATEG using the CSTR([SURVCATEGORY]) formula without success in the LicYes field: IIf([STRCATEG] Like "*I ....... Still a data mismatch

    I am missing something obvious here that for some reason I am missing. Any help appreciated

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    you can't use a date and a text value in the same field. that's why you're getting a data mismatch. If you want it to *appear* as a date or a 'no' then you'll need something like:

    LicYes: IIf([survcateg] Like "*I*",cstr([Exit_Date]),IIf([survcateg] Like "*E*",cstr([Exit_Date]),"No"))

    where you are explicitly changing the date field to a string. Just bear in mind you will not be able to (in most cases) perform any sort of operation on this field treating it as a date.



  3. #3
    AndyDandy is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Mar 2018
    Posts
    7
    Thanks rpeare, that solved the data type mismatch. What confuses me though is that if I only filtered like "I" and "E" survcateg records then the LicYes calculation displaying the [exitdate] and "No" would work and there would be no data mismatch error. Knowing what to change though is more satisfying than knowing the answer to this confusion.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    It really depends on what your data looks like. Because you were not explicitly changing your dates so they appeared as strings it is possible your individual datasets may run fine, it's when it actually has to mix dates and text in the same column where the problem occurs. So for instance if you had a version of this query where *all* the results either had or didn't have an exit date, there would be no problem.

    p.s. mark it solved if it's solved please!

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

Similar Threads

  1. Replies: 11
    Last Post: 07-14-2017, 11:13 AM
  2. Replies: 8
    Last Post: 03-14-2017, 02:36 PM
  3. Replies: 3
    Last Post: 08-10-2016, 11:26 AM
  4. Replies: 1
    Last Post: 05-11-2012, 10:59 AM
  5. Query Criteria Causing Data Mismatch Error
    By jrubenol in forum Queries
    Replies: 2
    Last Post: 09-14-2011, 09:34 AM

Tags for this Thread

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