Solved

#error in switch function

Posted on 2014-01-09
6
595 Views
Last Modified: 2014-01-29
Experts. I have a pretty complex query in our Access database. It displays the income guidelines for our apartment buildings. I used to use nested iif statements but there got to be too many different income limit percentages so I have to change my equations to the switch function.

Everything works/displays fine but we have 'previous year' buttons that display the limits from the past. When I click this button to go to a previous year and then close that screen to go back to the current year all my textboxes (which house the results from the switch function) turn to #error.

I have tried:
1. closing all these income limits screens and re-opening fresh thinking the same table is opening in both record sources and it doesn't like that but that didn't change anything.
2. also renamed text boxes on the screen to make sure they didn't match the actual field name. That didn't change anything.

I can attach the actual database if need be, it will just take some time. Please let me know if that would be helpful. Attached are some screen shots of the database and a text document with a snippet of the SQL.
before.jpg
after.jpg
switch.txt
0
Comment
Question by:acramer_dominium
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Ashok
ID: 39768903
Switch evaluates all of the expressions, even though it returns only one of them. For this reason, you should watch for undesirable side effects. For example, if the evaluation of any expression results in a division by zero error, an error occurs.
0
 

Author Comment

by:acramer_dominium
ID: 39768934
Ok. That makes sense. There will be only one of those expression that returns a 'true'. Why does it work on the first viewing of the screen though and then error out after you open another screen and go back to it?
0
 
LVL 13

Expert Comment

by:Ashok
ID: 39768967
It looks like
data returned might be null (when it is not working) because I see error in all of them.

I do not have MS Access and not an expert.

Is there a way for you to run the application in the DEBUG mode?

then just before you try to get to the screen where error shows up, put a breakfront in the code (on the SWITCH statement).  Inspect values.

HTH
Ashok
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:acramer_dominium
ID: 39769136
The SQL is all in a query there's no debugging that can be done. The data returned is not null there is a dollar amount that the statement returns.
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 39773087
Ashok is correct that Switch will evaluate all the expressions, and not just stop when it finds the first true condition.  For more about Switch: http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_3556-Using-the-Switch-Function-in-Microsoft-Access.html

To really troubleshoot this we will need a copy of the DB.
0
 

Author Closing Comment

by:acramer_dominium
ID: 39818078
Looking for another alternative
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now