Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
And Or in VBA
Dan Jackson 
            
3 years ago
Real Quick She Said!!!

If Control1 = X AND Control2 = Y Or Control2 = Z Then

Does The OR in this IF statement include the Control 1? Essentially, I want to

Check Control1 = X

If True Then

Control2 can be Y or Z
  -  True  -  


===========Or Does It Do This (Which would be wrong)=============


Check Control1 = X AND Control2 = Y
  -  True  -  

OR

Check Control2 = Z


Thanks. Trying to explain the options was really hard *Scratches head*!
Alex Hedley  @Reply  
           
3 years ago
Might need to think about adding brackets
Kevin Robertson  @Reply  
          
3 years ago
I would probably write it like this:
If (Control1 = X) AND (Control2 = Y Or Control2 = Z) Then
Or
If (Control1 = X AND Control2 = Y) Or (Control2 = Z) Then

Parentheses make a difference and makes it easier to read. ***In my humble opinion***
Dan Jackson OP  @Reply  
            
3 years ago
Something new learned today! Thanks fellas
Scott Axton  @Reply  
        
3 years ago

Operator Precedence in Visual Basic


Precedence Rules

    When expressions contain operators from more than one category, they are evaluated according to the following rules:

    The arithmetic and concatenation operators have the order of precedence described in the following section, and all have greater precedence than the comparison, logical, and bitwise operators.

    All comparison operators have equal precedence, and all have greater precedence than the logical and bitwise operators, but lower precedence than the arithmetic and concatenation operators.

    The logical and bitwise operators have the order of precedence described in the following section, and all have lower precedence than the arithmetic, concatenation, and comparison operators.

    Operators with equal precedence are evaluated left to right in the order in which they appear in the expression.

Overriding Precedence and Associativity

You can use parentheses to force some parts of an expression to be evaluated before others. This can override both the order of precedence and the left associativity. Visual Basic always performs operations that are enclosed in parentheses before those outside. However, within parentheses, it maintains ordinary precedence and associativity, unless you use parentheses within the parentheses.
Dan Jackson OP  @Reply  
            
3 years ago
Pemdas / Bodmas

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 12:10:50 PM. PLT: 4s