PDA

View Full Version : If-then-else statements in Access?



Beaver
09-19-2008, 02:13 PM
Newbie here!

I learned access and programming in school, but have since forgotten it. I have data imported into my Access database every day. There are 4 queries on a form within that database that the guys use depending on what metal type they are currently working with. The majority of this imported data is chemistry information, 19 elements in all. If the numbers are within tolerance for a specific metal lot, it is released etc.

My question IS:

How would I write code (probably a series of if then statements) that starts at metal lot 41745 and looks at the output for oxygen, if it is within tolerance, it moves to iron and so on. If all 7 elements are met, I want the output to be 6-4. If 5 of 7 are met(depending on the elements) , I want output to be 1299A and so on for each metal lot.

Any information or direction would be greatly appreciated! Thanks.

OBP
09-20-2008, 06:31 AM
Hello and welcome to the Forum.
You can use If then statements and also the "Case" statement to do the testing.
You could use a Form to step through the Records but a Recordset would be better. You will then need a For/next or Do/While Loop to step through the records to do the checking. What will you output the "Results" to?
It may even be possible to do this without VBA and just use a Query, but I am not sure.

asingh
09-21-2008, 03:39 AM
Could you post a scaled down version of your data base...here..

Beaver
09-23-2008, 08:54 AM
Could you post a scaled down version of your data base...here..


I decided to export my access queries to excel. Easier to manipulate. Now I just need to write IF formulas!

CreganTur
09-23-2008, 09:21 AM
Now I just need to write IF formulas!

Welcome to the forums- always good to see new members.

Without more information, or seeing example code I can only make educated guesses on how your code works.

For each of your tests I'm going to assume you have a counter variable that will increase by 1 for each test that it passes. If this is true, then you can use Select Case statements to set your output based on the counter variable. It would look something like:

Select Case Counter
Case 7
Output = "6-4"
Case 5
Output = "1299A"
End Select

just fill it in with all your options.

HTH:thumb