Solved

#error in switch function

Posted on 2014-01-09
6
607 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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