[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Access Code to check data for acceptable answer

Hello Experts.

I need your help with the below code.  I'm trying to have this code evaluate the content of an imported text field.  The field can only have 1 of 5 possible results (yes, y, no, n, and Null).  The evaluation should not be case sensitive.

The code below is giving me a Type mismatch error.

Thanks in advance for your help.

Function chkYesNo(ByVal varValue As Variant) As Boolean
    'Check if varValue is Null, Y, Yes, N, No
If varValue = "yes" Or "y" Or "no" Or "n" Then
    chkYesNo = True
Else
    chkYesNo = IsNull(varValue)
End If
       
End Function

Open in new window

0
dhemple
Asked:
dhemple
  • 2
1 Solution
 
PatHartmanCommented:
You always have to repeat the field you are comparing to.
If fldA = "yes" OR fldA = "n" or fldA = "no"..

Once there gets to be more then three options, a Case statement is usually simpler to read.
Function chkYesNo(ByVal varValue As Variant) As Boolean
    'Check if varValue is Null, Y, Yes, N, No
Select Case varValue
    Case "yes", "y", "no", "n"     
        chkYesNo = True
    Case Else
        chkYesNo = IsNull(varValue)
End Select       
End Function

Open in new window

0
 
NorieCommented:
Your if statement isn't quite right.
Function chkYesNo(ByVal varValue As Variant) As Boolean
    'Check if varValue is Null, Y, Yes, N, No
If varValue = "yes" Or varValue ="y" Or varValue ="no" Or varValue = "n" Then
    chkYesNo = True
Else
    chkYesNo = IsNull(varValue)
End If
       
End Function
 

Open in new window

0
 
dhempleAuthor Commented:
Thanks for your help Pat. I really do appreciate your continued support.  Until my next question, take care :)
0
 
PatHartmanCommented:
Thank you.  Good luck.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now