Multiple If or Case - Someone have a better, faster way?

  • Thread starter Thread starter OMS
  • Start date Start date
O

OMS

Hi,

I would like to put multiple reports in an If statement without using
multiple ElseIf's (I have a few ElseIf's already). This is in a On_Click
event.

I have several with reports with similar names and was wondering if there is
some wildcard I could use ie.

If strDoc = ("*_report*) Then

or is there a way to use "Or" in the structure ie.

If strDoc = ("XYZ_report1" Or "XXX_report2" Or "XYZ_report3") Then

I've tried these and get "Type mismatch" or nothing (I haven't trapped the
error yet)

Would Select Case be a better method than If Then? Any advice?

Thanks in advance.

OMS
 
Personally, when there's more than 2 options, I prefer the Select Case, as I
find it's easier to follow and modify...
 
Thank Susan,

Any solution for the first part of the question? Multiple expressions in a
single line?

OMS
 
Sorry, missed that part. With multiple operands (AND, OR) you need to define
each in entirety:
If strDoc = "XYZ_report1" Or strDoc = "XXX_report2" Or strDoc =
"XYZ_report3" Then
You can chop lines to make it more readable:
If strDoc = "XYZ_report1" _
Or strDoc = "XXX_report2" _
Or strDoc = "XYZ_report3" Then
 
Back
Top