How to Reduce a Switch from 2 or 3 to One?

T

Telesphore

I would like to convert the following Switch:

Program:

Switch (

[ProgNone]=-1;"None";

[ProgBA]=-1;"Bachelor of Arts";

[ProgSocSci]=-1;"Bachelor of Social Sciences";

[ProgMDiv]=-1;"Master of Divinity";

[ProgMPh]=-1;"Major in Philosophy";

[ProgCPh]=-1;"Certificate in Philosophy")



because some students take 2 or 3 programs and we need to write only one of
their programs in a report.


Thank you in advance
 
V

Van T. Dinh

The Switch() function is evaluated from left to right and will only return
the value associated with the _first_ Boolean expression that evaluates to
True.
 
T

Telesphore

Thank you,

Instead of the Switch() function, would it be possible to use de IIf()
function to solve the problem?

For example if a student is taking Social Sciences in the Winter term,
Philosophy in the Summer term and no program in the Fall term, I need to
write only one of those 3 in the control box of a report.

Some students are taking at least one program, somme two, others are takin
3.

So it would be like this:

If exists a program in the Winter term, write the program of the Winter
term, or write the program of the Summer term, if exists, or write the
program of the Fall term.

Thank you.


The Switch() function is evaluated from left to right and will only return
the value associated with the _first_ Boolean expression that evaluates to
True.

--
HTH
Van T. Dinh
MVP (Access)


I would like to convert the following Switch:

Program:

Switch (

[ProgNone]=-1;"None";
[ProgBA]=-1;"Bachelor of Arts";
[ProgSocSci]=-1;"Bachelor of Social Sciences";
[ProgMDiv]=-1;"Master of Divinity";
[ProgMPh]=-1;"Major in Philosophy";
[ProgCPh]=-1;"Certificate in Philosophy")

because some students take 2 or 3 programs and we need to write only one
of >> their programs in a report.
 
V

Van T. Dinh

It sounds to me a VBA UDF (User-Defined function) is more suitable rather
than trying a single statement.

Check Access VB Help / Access programming books on UDF.

--
HTH
Van T. Dinh
MVP (Access)


Telesphore said:
Thank you,

Instead of the Switch() function, would it be possible to use de IIf()
function to solve the problem?

For example if a student is taking Social Sciences in the Winter term,
Philosophy in the Summer term and no program in the Fall term, I need to
write only one of those 3 in the control box of a report.

Some students are taking at least one program, somme two, others are takin
3.

So it would be like this:

If exists a program in the Winter term, write the program of the Winter
term, or write the program of the Summer term, if exists, or write the
program of the Fall term.

Thank you.


The Switch() function is evaluated from left to right and will only return
the value associated with the _first_ Boolean expression that evaluates to
True.

--
HTH
Van T. Dinh
MVP (Access)


I would like to convert the following Switch:

Program:

Switch (

[ProgNone]=-1;"None";
[ProgBA]=-1;"Bachelor of Arts";
[ProgSocSci]=-1;"Bachelor of Social Sciences";
[ProgMDiv]=-1;"Master of Divinity";
[ProgMPh]=-1;"Major in Philosophy";
[ProgCPh]=-1;"Certificate in Philosophy")

because some students take 2 or 3 programs and we need to write only
one
of >> their programs in a report.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top