?
Solved

VBA "or"  Statement, parentheses   in correct place.

Posted on 2011-09-07
10
Medium Priority
?
336 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

762 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