Solved

#error in switch function

Posted on 2014-01-09
6
601 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

813 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

11 Experts available now in Live!

Get 1:1 Help Now