Thanks SJ. I may be able to get that to work. I thought I had seen something else...
Say if I need to do something like the following:
Code:
If strMyName = "Smith" then
me!textbox = "Hello"
ElseIf strMyName = "Jones" then
me!textbox = "Hello"
ElseIf strMyName = "Harris" then
me!textbox = "Hello"
Else
strMyName = "Goodbye"
End if
If nIsIn(true, true, strMyValue, "SomeText1","SomeText2","SomeText3") > 0 then
Do stuff
end if
'or
If nIsIn(True, True, strMyName, "Smith", "Jones", "Harris") > 0 then
me!textbox = "Hello"
Else
' strMyName = "Goodbye" (SIC)
me!textbox = "Goodbye"
End if
Code:
Public Function nIsIn(ByVal bMatchCase As Boolean, ByVal bMatchEntire As Boolean, ByRef szSought As String, ParamArray varSearchIn()) As Integer
'Returns 0 if szSought not in varSearchIn, as restricted by bMatchCase and bMatchEntire
'or the (one based) index number of the first array element to satisfy the requirements
'or -1 if an error occurred
On Error GoTo nIsIn_Err
Dim nCounter As Integer
Dim nIndexIncrement As Integer
Dim nPos As Integer
Dim nCompare As Integer
'Assume negative result
nIsIn = 0
If bMatchCase = True Then
nCompare = vbBinaryCompare
Else
nCompare = vbTextCompare
End If
'ParamArray is always Zero Based array in AC97, regardless of Option Base statement
'However who knows how this may change in future versions....
If LBound(varSearchIn) = 0 Then
nIndexIncrement = 1
ElseIf LBound(varSearchIn) = 1 Then
nIndexIncrement = 0
Else
Err.Raise vbObjectError + 1001, "nIsIn", "Unusable Array Structure"
End If
For nCounter = LBound(varSearchIn) To UBound(varSearchIn)
If Len(Nz(varSearchIn(nCounter))) > 0 Then
If bMatchEntire Then
If StrComp(szSought, varSearchIn(nCounter), nCompare) = 0 Then
nIsIn = nCounter + nIndexIncrement
Exit Function
End If
Else 'Not bMatchEntire
nPos = InStr(1, varSearchIn(nCounter), szSought, nCompare)
If nPos > 0 Then
nIsIn = nCounter + nIndexIncrement
Exit Function
End If
End If
Else 'varSearchIn(nCounter) is null or zero length string
If szSought = vbNullString Then
nIsIn = nCounter + nIndexIncrement
Exit Function
End If
End If
Next nCounter
nIsIn_Exit:
Exit Function
nIsIn_Err:
nIsIn = -1
MsgBox "An error occurred in nIsIn" & vbCrLf & "Error Number : " & Err.Number & vbCrLf & "Error Description : " & Err.Description & vbCrLf & "Error Source : " & Err.Source, vbOKOnly + vbInformation, "nIsIn Error"
End Function