Solved

#error in switch function

Posted on 2014-01-09
6
591 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

706 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

18 Experts available now in Live!

Get 1:1 Help Now