Results 1 to 4 of 4
  1. #1
    Hillsy7 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    2

    Data mismatch when sorting.

    Hi all,

    Having an issue here - not overly experienced with access and can't work out where things are going wrong....

    I Have a table of information about items....I needed to run a query which removed certain Items if they were similar to others (secondary or lesser versions)....I did this in excel simple enough with a macro, so I created a user defined function in Access to mimic the macro, called DeleteISBNInfo()

    Code:
    Public Function DeleteISBNInfo(Pubdate As Date, Title As String, Format As String, Binding As Variant) As Integer
    
    
    If Not IsNull(Format) And Not IsNull(Title) And Not IsNull(Pubdate) Then
        If Format = "epub" Then
                DeleteISBNInfo = DCount("*", "ISBN info", "[Pub Date] = #" & Pubdate & "# AND [Title] = '" & Replace(Title, "'", "''") & "' AND [Format] = 'B Format'") _
                + DCount("*", "ISBN info", "[Pub Date] = #" & Pubdate & "# AND [Title] = '" & Replace(Title, "'", "''") & "' AND [Format] = 'A Format'") _
                + DCount("*", "ISBN info", "[Pub Date] = #" & Pubdate & "# AND [Title] = '" & Replace(Title, "'", "''") & "' AND [Format] = 'Demy'") _
                + DCount("*", "ISBN info", "[Pub Date] = #" & Pubdate & "# AND [Title] = '" & Replace(Title, "'", "''") & "' AND [Format] = 'Royal'")
        ElseIf Format = "A Format" Or Format = "Royal" Then
            DeleteISBNInfo = DCount("*", "ISBN info", "[Pub Date] = #" & Pubdate & "# AND [Title] = '" & Replace(Title, "'", "''") & "' AND [Format] = 'B Format'")
        ElseIf Format = "Demy" Then
            DeleteISBNInfo = DCount("*", "ISBN info", "[Pub Date] = #" & Pubdate & "# AND [Title] = '" & Replace(Title, "'", "''") & "' AND [Format] = 'Royal'")
        ElseIf Binding = "Trade Paperback" Then
            DeleteISBNInfo = DCount("*", "ISBN info", "[Pub Date] = #" & Pubdate & "# AND [Title] = '" & Replace(Title, "'", "''") & "' AND [Edition Binding] = 'Hardback'")
        Else
            DeleteISBNInfo = 0
        End If
    End If
    
    
    End Function
    So when I created a query and added this function into an additional column to the table.....worked perfectly! There were zeros when there wasn't a similar product up the chain, and a non-zero count if there was. Great!

    ...Not so great....when I attempted to sort on the column containing this formula, I got the "Data Type Mismatch in Criteria Expression" error. I can sort the table fine by any other field...just not this one..

    .....I don't understand!!! Why?!?!?!!



    Any help would be greatly appreciated!

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    So when I created a query and added this function into an additional column to the table.....worked perfectly!
    I bet if you were to scroll down the entire query result you will find one or more #errors

    you probably have some nulls because

    If Not IsNull(Format) And Not IsNull(Title) And Not IsNull(Pubdate) Then

    if any of these is null then you are not assigning a value to DeleteISBNInfo

    try modifying the end of you function to

    Code:
        ...
        ...
        Else
            DeleteISBNInfo = 0
        End If
    
    Else
       DeleteISBNInfo = 0
    End If
    
    
    End Function

  3. #3
    Hillsy7 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    2
    AH FFS!!!!!

    1! 1 error in 5000+ records!!!!!

    Thanks a bunch!! - didn't know having #errors screwed up sorts....I know what to look for now (Also had to switch the string to variant to allow nulls, but did that before.

    I have learned....thanks again

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    Also be aware that although Format is not a reserved word, it is a function and also a property for controls, fields etc. Using it might cause a problem in another situation

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

Similar Threads

  1. Data mismatch
    By cbende2 in forum Access
    Replies: 13
    Last Post: 06-05-2015, 01:18 PM
  2. Data Mismatch in Criteria
    By SpdRacerX in forum Queries
    Replies: 12
    Last Post: 04-03-2012, 12:56 PM
  3. Data Type Mismatch in SQL
    By Phred in forum Queries
    Replies: 2
    Last Post: 01-04-2012, 03:40 PM
  4. Data Type Mismatch
    By timmy in forum Programming
    Replies: 9
    Last Post: 04-12-2011, 03:48 AM
  5. Data Mismatch?
    By Lockrin in forum Access
    Replies: 7
    Last Post: 06-14-2010, 03:17 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