Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA "or"  Statement, parentheses   in correct place.

Posted on 2011-09-07
10
Medium Priority
?
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 49

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 500 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 49

Assisted Solution

by:Martin Liss
Martin Liss earned 500 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 49

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 500 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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

610 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