Results 1 to 10 of 10
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Type Mismatch....WHY?!!?

    I have the below piece of code as criteria in a query. For some reason I keep getting a type mismatch error! I checked the table and the field is formatted to Date/Time. Can someone please lay a fresh set of eyes on this? Thank you.



    Code:
    Between CDate(IIf(DatePart("m",Date())=1,CDate("12/31/" & DatePart("yyyy",Date())-1),CDate(DatePart("m",Date())-1 & "/1/" & DatePart("yyyy",Date())))) And CDate(IIf(DatePart("m",Date())=1,CDate("12/31/" & DatePart("yyyy",Date())-1),CDate(DatePart("m",Date())-1 & "/31/" & DatePart("yyyy",Date()))))

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    first. sorted out....
    Quote Originally Posted by jgelpi16 View Post

    Code:
    Between CDate(IIf(DatePart("m",Date())=1,CDate("12/31/" & 
    
    DatePart("yyyy",Date())-1),CDate(DatePart("m",Date())-1 & "/1/" & 
    
    DatePart("yyyy",Date())))) And Date(IIf(DatePart("m",Date())=1,
    
    CDate("12/31/" & DatePart("yyyy",Date())-1),CDate(DatePart("m",Date())-1 & 
    
    "/31/" & DatePart("yyyy",Date()))))
    maybe you need to wrap it in pound signs? like:
    Code:
    between "#" & IIF() statement & "#" AND 
    
    "#" & IIF() statement & "#"
    or maybe take the cdate() functions out of it? believe or not, that might work!

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Can you tell us in English what the criteria is meant to do?

  4. #4
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    The criteria needs to filter for last month's date. If this month is January I have to back up to the previous year as well. Hence the portion with "12/1/" & Datepart("yyyy", Date()-1.

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    maybe you need to wrap it in pound signs? like:
    Code:
    between "#" & IIF() statement & "#" AND

    "#" & IIF() statement & "#"
    or maybe take the cdate() functions out of it? believe or not, that might work!
    Tried both methods....no luck.

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    maybe the problem is the fact that you can't have IIF() statements in criteria statements?

    now that I think about it, I think I read that somewhere. Either that, or Paul Baldy might have mentioned it once. I would seriously think about taking those out and testing it. I'm kind of thinking that's it. Either that, or IIF() statements can't be in BETWEEN statements...

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I discovered the issue...I know the statement works because it worked last month. I was under the incorrect impression that if you just every month the 31st it would accept that as the end of the month. I was wrong. If I can the "/31/" to "/28/" (since last month only had 28 days) the code works fine. I'll have to go about another method to find the end of the month.

  8. #8
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    And the solution....

    Code:
    Between CDate(IIf(DatePart("m",Date())=1,CDate("12/1/" & DatePart("yyyy",Date())-1),CDate(DatePart("m",Date())-1 & "/1/" & DatePart("yyyy",Date())))) And CDate(IIf(DatePart("m",Date())=1,CDate("12/31/" & DatePart("yyyy",Date())-1),cdate(DateSerial(Year(Date()), Month(Date()), 0)))))

  9. #9
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by jgelpi16 View Post
    I discovered the issue...I know the statement works because it worked last month. I was under the incorrect impression that if you just every month the 31st it would accept that as the end of the month. I was wrong. If I can the "/31/" to "/28/" (since last month only had 28 days) the code works fine. I'll have to go about another method to find the end of the month.
    I'm laughing at this, simply because I could've probably given you this exact same answer if I would've analyzed your post completely. But I didn't, so hence you found it on your own. Way to go!

  10. #10
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    You were just letting me find the answer on my own .

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

Similar Threads

  1. DCount type mismatch
    By jonesy29847 in forum Programming
    Replies: 6
    Last Post: 02-25-2011, 09:59 PM
  2. Type Mismatch
    By Alex Motilal in forum Programming
    Replies: 10
    Last Post: 02-13-2011, 05:42 AM
  3. Type mismatch
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 08-07-2010, 06:54 AM
  4. data type mismatch
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 08-02-2010, 04:15 PM
  5. Type Mismatch - HELP!
    By jgelpi in forum Programming
    Replies: 3
    Last Post: 07-17-2009, 03:53 PM

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