Data mismatch in criteria question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am running a query on Sales data, which contains Opportunity Status and
Fallout Reason field. In the Opp. Status field, the options are Closed or
Closed-Won. In the case where the status is Closed, the Fallout reason will
have a list of various different reasons, such as No-Bid, Cancelled,
LOST-PRICE, LOST-SPEED, etc. I need to have a single number each for Lost,
No-Bid, Cancelled, and Won. I have written some VBA code to assist with this:
Function GetStatus(ByVal strStatus As String, Optional strFallout As String
= "") _ As String
If strStatus <> "Closed-Won" Then
If (Left(strFallout, 4) <> "LOST") Then
GetStatus = strFallout
Else
GetStatus = "Lost"
End If
Else
GetStatus = strStatus
End If
End Function

When I run this in my query, I receive a Data Mismatch in criteria error.
Please help!
 
Do you have fields in your table where the value you're passing to the
function is Null?

You have two options.

One is to change strStatus to Variant in your function declaration, and add
logic in the function to handle Null values.

The other is to pass Nz([MyFieldThatMayBeNull], "") to the function, rather
than strictly the field.
 
Thank you much, I changed the datatype to a Variant and it works properly!

Douglas J. Steele said:
Do you have fields in your table where the value you're passing to the
function is Null?

You have two options.

One is to change strStatus to Variant in your function declaration, and add
logic in the function to handle Null values.

The other is to pass Nz([MyFieldThatMayBeNull], "") to the function, rather
than strictly the field.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



JHARRIS133 said:
I am running a query on Sales data, which contains Opportunity Status and
Fallout Reason field. In the Opp. Status field, the options are Closed or
Closed-Won. In the case where the status is Closed, the Fallout reason
will
have a list of various different reasons, such as No-Bid, Cancelled,
LOST-PRICE, LOST-SPEED, etc. I need to have a single number each for
Lost,
No-Bid, Cancelled, and Won. I have written some VBA code to assist with
this:
Function GetStatus(ByVal strStatus As String, Optional strFallout As
String
= "") _ As String
If strStatus <> "Closed-Won" Then
If (Left(strFallout, 4) <> "LOST") Then
GetStatus = strFallout
Else
GetStatus = "Lost"
End If
Else
GetStatus = strStatus
End If
End Function

When I run this in my query, I receive a Data Mismatch in criteria error.
Please help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top