0

DocNum is set as Double, I have numbers that when they fall into these buckets should trigger different code to be used. I'm having trouble identifying why it's only using the if stmt and not the elseif. The stmt returns true everytime...

Example: 1003xxxxx should return true and use the if stmt code, 1900xxxxxx should return false and use the elseif code. But 1900xxxxxx is using the if stmt code...

It's most likely the wildcard, but I was under the assumption that it would need to satisfy the previous numbers before assuming the remaining numbers.

If DocNum = "1003*" Or "1004*" Or "1005*" Then
'Some Code
ElseIf DocNum = "19*" Or "17*" Or "22*" Or "20*" Then
'Some Code
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
iLL-Army
  • 41
  • 1
  • 8
  • If `DocNum` is a `Double`, use math, not string comparisons (i.e. `Fix(DocNum / (10 ^ 5))`) . You also need a *full expression* for each of the `Or` clauses. What this is doing now is basically `CBool("1004*")`, which is a type mismatch. – Comintern Feb 20 '19 at 21:55
  • 1
    The linked duplicate addresses the `If DocNum = "abc" Or DocNum = "xyz"` vs `If DocNum = "abc" Or "xyz"` part of the question. Note that the `=` operator is an *equality* operator: this operation doesn't support wildcards. Look into the `Like` operator if you need wildcards. – Mathieu Guindon Feb 20 '19 at 21:57

1 Answers1

-2

Tried This solved:

If DocNum = "1003*" Or _
   DocNum = "1004*" Or _
   DocNum = "1005*" Then
 'Some Code
ElseIf
   DocNum = "19*" Or _
   DocNum = "17*" Or _
   DocNum = "22*" Or _
   DocNum = "20*" Then
 'Some Code

Or

Select Case DocNum
   Case "1003*","1004*","1005*"
   'Some Code
   Case "19*","17*","22*","20*"
   'Some Code
   Case Else
   'Some Code Case None
End Select
Djemoui
  • 77
  • 7