Solved

VBA "or"  Statement, parentheses   in correct place.

Posted on 2011-09-07
10
331 Views
Last Modified: 2012-08-13
VBA "or"  Statement, parentheses in correct place. I am using paranthesis in my "or" statement.
I just wanted to check and make sure that they are in the right place.  Mostly i am concerned with the beginning and ending parentheses in my statement.

Here is the code:
ElseIF (rstMasterView("TREE_SPECIES_CD") = 4010 Or rstMasterView("TREE_SPECIES_CD") = 4011 Or rstMasterView("TREE_SPECIES_CD") = 4012 Or rstMasterView("TREE_SPECIES_CD") = 4014 Or rstMasterView("TREE_SPECIES_CD") = 4015 Or rstMasterView("TREE_SPECIES_CD") = 4018) then
Thanks.
0
Comment
Question by:donnie91910
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 36497265
It seems to be okay but I don't believe you need the beginning and ending parentheses.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 125 total points
ID: 36497267
They appear fine to me, however given the statement you posted you don't really need them. You really only need to consider using surrounding parentheses when you have a mix of AND and OR statements, since one binds tighter than the other (IIRC, AND binds tighter than OR, but I can't immediately recall). If you have a homogenous list of boolean operators, then you can simple avoid using the outer parens.
0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 125 total points
ID: 36497293
Does VBA have Select Case

Select Case (rstMasterView("TREE_SPECIES_CD")
    Case 4010, 4011, 4012, 4014, 4015, 4018
        ' Do something
    Case <other values>
        ' Do something else
    Case Else
        ' ' blah
End Select

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 36497306
Sorry, first line s/b

Select Case rstMasterView("TREE_SPECIES_CD")
0
 
LVL 10

Assisted Solution

by:plummet
plummet earned 125 total points
ID: 36497339
Yup, all looks OK if a bit complicated. You might find it easier to assign the value to a variable and test that, like this:

dim iSpeciesCD as integer

iSpeciesCD = rstMasterView("TREE_SPECIES_CD")

if (your code here)...............
ElseIF iSpeciesCD = 4010 Or iSpeciesCD = 4011 Or iSpeciesCD = 4012 Or iSpeciesCD = 4014 Or iSpeciesCD = 4015 Or iSpeciesCD = 4018 then

Open in new window


Just makes it a bit easier to read!
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 36497655
Yes, VBA has Select Case, and I would use it in this case.  Here is some typical Select Case code:
Select Case intChoice
   
      Case 0
         GoTo ErrorHandlerExit
   
      Case 1
         Call SendAcknowledgement(Me, lngID, strUserAID)
         
      Case 2
         Call CreateFirstReport(Me, lngID, strUserAID)
         
      Case 3
         Call CreateStatusReport(Me, lngID, strUserAID)
         
      Case 4
         strTemplate = "Dunn 1.dotx"
         Call PrintLetter(lngID:=lngID, _
            strUserAID:=strUserAID, _
            strWordTemplate:=strTemplate, _
            strInsured:=strInsured, _
            strClaimant:=strClaimant, _
            frm:=Me, _
            strAppraiser:=strAppraiser, _
            strEmailType:="Envelope")
      
      Case 5
         strTemplate = "Dunn 1.dotx"
         Call PrintLetter(lngID:=lngID, _
            strUserAID:=strUserAID, _
            strWordTemplate:=strTemplate, _
            strInsured:=strInsured, _
            strClaimant:=strClaimant, _
            frm:=Me, _
            strAppraiser:=strAppraiser, _
            strEmailType:="Attachment")
      
      Case 6
         strTemplate = "Dunn 2.dotx"
         Call PrintLetter(lngID:=lngID, _
            strUserAID:=strUserAID, _
            strWordTemplate:=strTemplate, _
            strInsured:=strInsured, _
            strClaimant:=strClaimant, _
            frm:=Me, _
            strAppraiser:=strAppraiser, _
            strEmailType:="Envelope")
      
      Case 7
         strTemplate = "Dunn 2.dotx"
         Call PrintLetter(lngID:=lngID, _
            strUserAID:=strUserAID, _
            strWordTemplate:=strTemplate, _
            strInsured:=strInsured, _
            strClaimant:=strClaimant, _
            frm:=Me, _
            strAppraiser:=strAppraiser, _
            strEmailType:="Attachment")
           
      Case 8
         strTemplate = "Dunn 3.dotx"
         Call PrintLetter(lngID:=lngID, _
            strUserAID:=strUserAID, _
            strWordTemplate:=strTemplate, _
            strInsured:=strInsured, _
            strClaimant:=strClaimant, _
            frm:=Me, _
            strAppraiser:=strAppraiser, _
            strEmailType:="Envelope")
      
      Case 9
         strTemplate = "Dunn 3.dotx"
         Call PrintLetter(lngID:=lngID, _
            strUserAID:=strUserAID, _
            strWordTemplate:=strTemplate, _
            strInsured:=strInsured, _
            strClaimant:=strClaimant, _
            frm:=Me, _
            strAppraiser:=strAppraiser, _
            strEmailType:="Attachment")
      
   End Select

Open in new window

0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 36497659
This is Access VBA, but Select Case works in Excel VBA too.
0
 
LVL 31

Assisted Solution

by:Helen_Feddema
Helen_Feddema earned 125 total points
ID: 36497672
I would set a String variable (strTreeSpecies) to the field value, and check that it is not empty or Null, then set up a Select Case statement for the possible values of strTreeSpecies.
0
 
LVL 10

Expert Comment

by:plummet
ID: 36497985
Select case would indeed be a neater way of doing this
0
 

Author Closing Comment

by:donnie91910
ID: 36498143
thank you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now