Link to home
Start Free TrialLog in
Avatar of donnie91910
donnie91910

asked on

VBA "or" Statement, parentheses in correct place.

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.
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

It seems to be okay but I don't believe you need the beginning and ending parentheses.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, first line s/b

Select Case rstMasterView("TREE_SPECIES_CD")
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

This is Access VBA, but Select Case works in Excel VBA too.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Select case would indeed be a neater way of doing this
Avatar of donnie91910
donnie91910

ASKER

thank you.