Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Data Type Mismatch

    I have a query (see design screenshot below) that executes correctly UNTIL I add True or False as the criteria for the "IsToday". All elements of the criteria are Boolean, so what's the beef?
    Code:
    Public Function BirthDay(AnnDate As Date) As Boolean
    Click image for larger version. 

Name:	AllBoolean.jpg 
Views:	42 
Size:	98.0 KB 
ID:	50871



    BTW, the expression seen in the design view for "IsToday:" is used successfully in another of my queries, so I'm not suspicious of the function.

  2. #2
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    If you're not suspicious of the function, the underlying data has issues. Try to isolate chunks of data to find the rogue record(s). Once you find that, you can clean up the data.
    Please click on the ⭐ below if this post helped you.


  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    If I omit the function value from the criteria, the query runs perfectly and displays the function values as expected. The DB does not seem to be corrupted in any way, so I've not yet found the issue. (The date value set in the record done via Allen's date function)
    Screenshot snippet:
    Click image for larger version. 

Name:	000.jpg 
Views:	37 
Size:	12.8 KB 
ID:	50872

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try: =-1

    Which date function do you mean - SQLDate() found on http://allenbrowne.com/ser-36.html ?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Yes, I've tried to set criteria with both "0" and "-1" in lieu of TRUE & FALSE but same results.
    Allen wrote a calendar function years ago that I continue to use that sets the value of text boxes bound to date fields.
    Code:
    Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
    'On Error GoTo Err_Handler
        'Purpose:   Open the calendar form, identifying the text box to return the date to.
        'Arguments: txt = the text box to return the date to.
        '           strTitle = the caption for the calendar form (passed in OpenArgs).
        
        Set gtxtCalTarget = txt
        DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle
        
    Exit_Handler:
        Exit Function
    
    
    Err_Handler:
        MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation, "CalendarFor()"
        Resume Exit_Handler
    End Function
    I've moved the target records around in the DB such that the query would be operating on different records in the DB but nothing changed.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    That procedure just opens a form. It is declared as a function but returns nothing. It could just as well be a Sub. Some code behind that form does the real work.

    I am not finding anything about this on Allen's website.

    What is code for BirthDay() function?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Doesn't amount to much:
    Code:
    Public Function BirthDay(AnnDate As Date) As Boolean
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  We just need to isolate and compare the month and day based on
    '  sobriety date versus today's date.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    BirthDay = False
    If left(Format(AnnDate, "mm/dd/yyyy"), 5) = left(Format(Date, "mm/dd/yyyy"), 5) Then BirthDay = True
    End Function
    
    I could just as well put the code (adjusted) directly into the query.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Could. And that would be informative.

    I tested this function with my date field and it works with True/False criteria.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I agree, and I'll do that as soon as I can. Family awaits at the moment.

  10. #10
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Click image for larger version. 

Name:	001.jpg 
Views:	35 
Size:	37.8 KB 
ID:	50873

    Putting the test directly into the query design view works properly.

    What puzzles me the most is that I have another query that uses the function return as criteria without any issues.

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Why are you even bothering around with the year?

    Code:
    ? format(date,"mm/dd")
    10/09
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    No need, force of habit I guess.

    Code:
    IIf((Left(Format([SOBRTYDATE],"mm/dd"),5)=Left(Format(Date(),"mm/dd"),5)),-1,0)
    One, of course, needs the parentheses pair with the Date function or Access thinks it's a missing record field.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Test email notifications for Bill.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Notification went in the spam folder.

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The first rule you learn in IT is "reboot". The second is "check your spam folder".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Data Type Mismatch when Trying to Sum a Qry
    By Tuckejam in forum Queries
    Replies: 6
    Last Post: 07-07-2020, 10:58 AM
  2. Data Type MisMatch
    By Eranka in forum Access
    Replies: 4
    Last Post: 10-31-2019, 03:58 AM
  3. Data Type MisMatch
    By Eranka in forum Access
    Replies: 2
    Last Post: 10-23-2019, 04:43 AM
  4. data type mismatch
    By ottoc in forum Queries
    Replies: 1
    Last Post: 12-02-2014, 09:42 AM
  5. Data Type Mismatch
    By timmy in forum Programming
    Replies: 9
    Last Post: 04-12-2011, 03:48 AM

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