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 
Switch function
Roger Strate 
       
3 years ago
I have created a switch function for a field I have named "past due". I want the switch function to access the "Is Paid" field to determine if an invoice has been paid or not of if it is past due. The function works OK for until the "OrderT.DueDate" passes the current date minus 30 then the field changes to past due. Any suggestions to correct this?
Here is the switch code I have written. I will send a screen shot of my form.

=Switch([OrderT.DueDate]<Date()-30,"Past Due",[IsPaid],"Has Been Paid",[OrderT.DueDate]>=Date(),"Payment Not Due")
Roger Strate OP  @Reply  
       
3 years ago

Kevin Robertson  @Reply  
          
3 years ago

Roger Strate OP  @Reply  
       
3 years ago
Fantastic Kevin, thank you my friend. Big learning moment for me and I won't be forgetting the AND statement after this. (hopefully as I am old ha ha).
Kevin Yip  @Reply  
     
3 years ago
The Switch() function still won't work if all conditions are false, which would be the case if the due date is not yet 30 days old, the invoice still unpaid, and the due date is before today's date.  For instance, if the today's date is 4/24/23, and the due date is only 23 days ago (4/1/23), and [IsPaid] is also false, then all 3 conditions in the Switch() function will be false.  In that case, Switch() will return null instead.  You need to add one last condition that is guaranteed to be true, and add a return value for that.  This is necessary for Switch() in general:

    =Switch([OrderT.DueDate]<Date()-30 And Not [IsPaid], "Over 30 Days Past Due", [IsPaid], "Has Been Paid", [OrderT.DueDate]>=Date(), "Payment Not Due", True, "Less Than 30 Days Past Due")

If you find this cumbersome, you may rearrange the order of the conditions.  I would put the [IsPaid] condition in front, then check if it is over or less than 30 days past due:

   =Switch([IsPaid], "Paid", [OrderT.DueDate]>=Date(), "Payment Not Due", [OrderT.DueDate]<Date()-30, "Over 30 Days Past Due", True, "Less Than 30 Days Past Due")

The Switch() function looks at conditions from left to right, and as soon as a True condition is found, it stops looking at subsequent conditions.  So the most "decisive" condition should always be in front.

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/9/2026 3:01:32 AM. PLT: 1s