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!