473,473 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditional expression

4 New Member
Hi,

Anyone able to help me with this?

I am creating a query that includes YEAR and WKSLEFT, i would like to be able to determine the YRDUE by counting the amounts of WKSLEFT.

The range is:

Between 0 and 51 = year
Between 52 and 103 = year +1
Between 104 and 155 year +2

This is what i have tried to use but it only works for one condition, i dont know how to make the others work?

yeardue: IIf(([wksleft] Between '0' And '51'),[year],IIf(([wksleft] Between '52' And '103'),[year]+1))

can anyone help me with this please!?
Dec 2 '07 #1
3 1210
Jim Doherty
897 Recognized Expert Contributor
Hi,

Anyone able to help me with this?

I am creating a query that includes YEAR and WKSLEFT, i would like to be able to determine the YRDUE by counting the amounts of WKSLEFT.

The range is:

Between 0 and 51 = year
Between 52 and 103 = year +1
Between 104 and 155 year +2

This is what i have tried to use but it only works for one condition, i dont know how to make the others work?

yeardue: IIf(([wksleft] Between '0' And '51'),[year],IIf(([wksleft] Between '52' And '103'),[year]+1))

can anyone help me with this please!?

Hi Eliasam,

Welcome to the scripts!

Yes that can look rather tiresome to the eye particularly if the combinations became more than that.

I don't know how familar you are with functions but the SELECT CASE construct within a 'function' that returns a value to the query would assist you. It certainly reads better and you can always widen its scope with ease.

Paste the functional code below into a module immediately below the Option Compare Database line and use it as a calculated column in your query like so

YearDue: fn_YrDue([year],[wksleft])


Expand|Select|Wrap|Line Numbers
  1.  
  2. Function fn_YrDue(intYear As Integer, intWks As Integer) As Integer
  3.     On Error Resume Next
  4.     Select Case intWks
  5.     Case 0 To 51
  6.         fn_YrDue = intYear
  7.     Case 52 To 103
  8.         fn_YrDue = intYear + 1
  9.     Case 105 To 114
  10.         fn_YrDue = intYear + 2
  11.     Case Else
  12.         fn_YrDue = 0
  13.     End Select
  14. End Function
  15.  

Please note the Select case construct above will always return a zero if the resultant calculation falls outside of the ranges you specify. You might wish to amend it to return 'actually' what you want

Regards

Jim :)
Dec 2 '07 #2
FishVal
2,653 Recognized Expert Specialist
[year] + Int([wksleft]/52)

Though, I believe DateDiff() function would be preferable.
Dec 2 '07 #3
eliasam
4 New Member
Thanks Jim

works just fine!

I should read up on functions to make it less tiresome for me

Thanks again!

Elias :)














Hi Eliasam,

Welcome to the scripts!

Yes that can look rather tiresome to the eye particularly if the combinations became more than that.

I don't know how familar you are with functions but the SELECT CASE construct within a 'function' that returns a value to the query would assist you. It certainly reads better and you can always widen its scope with ease.

Paste the functional code below into a module immediately below the Option Compare Database line and use it as a calculated column in your query like so

YearDue: fn_YrDue([year],[wksleft])


Expand|Select|Wrap|Line Numbers
  1.  
  2. Function fn_YrDue(intYear As Integer, intWks As Integer) As Integer
  3.     On Error Resume Next
  4.     Select Case intWks
  5.     Case 0 To 51
  6.         fn_YrDue = intYear
  7.     Case 52 To 103
  8.         fn_YrDue = intYear + 1
  9.     Case 105 To 114
  10.         fn_YrDue = intYear + 2
  11.     Case Else
  12.         fn_YrDue = 0
  13.     End Select
  14. End Function
  15.  

Please note the Select case construct above will always return a zero if the resultant calculation falls outside of the ranges you specify. You might wish to amend it to return 'actually' what you want

Regards

Jim :)
Dec 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: neblackcat | last post by:
Would anyone like to comment on the following idea? I was just going to offer it as a new PEP until it was suggested that I post it here for comment & consideration against PEP 308. I'm far...
62
by: Reinhold Birkenfeld | last post by:
Hi, after Guido's pronouncement yesterday, in one of the next versions of Python there will be a conditional expression with the following syntax: X if C else Y which is the same as today's...
2
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another...
1
by: GGerard | last post by:
Hello Is there a way to use a variable in the Conditional Formatting of a Textbox? Example : I want the background of a textbox in a continuous form to change color when the value of...
11
by: Dan Noland | last post by:
A friend of mine asked me a C question that I couldn't answer. Could you guys weigh in? ---------- Forwarded message ---------- Date: Sun, 21 Nov 2004 21:08:27 -0500 From: Rick Kennell...
6
by: Chris Dunaway | last post by:
Consider this code (.Net 2.0) which uses a nullable type: private void button1_Click(object sender, System.EventArgs e) { DateTime? nullableDate; nullableDate = (condition) ? null :...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
4
by: Colin J. Williams | last post by:
It would be helpful if the rules of the game were spelled out more clearly. The conditional expression is defined as X if C else Y. We don't know the precedence of the "if" operator. From the...
15
by: Dan Henry | last post by:
I have run across functions in the Linux kernel's MTD driver that have me scratching my head a bit. The functions have the general form: extern int bar(size_t len, size_t *retlen, unsigned char...
15
by: Nicholas M. Makin | last post by:
I was just thinking that I understood the conditional operator when I coded the following expecting it to fail: int a= 10, b= 20, c= 0; ((a < b) ? a : b) = c; // a=0 a=20; b= 10; ((a < b) ? a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.