473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Trying to switch from really long nested IIf statement but having trouble...

In the interest of full disclosure, I must admit that this is the first time I have ever tried using Access, let alone worked with VB. I came up with an idea for an access database that will help me keep track of allowed and used vacation/personal time much easier and with fewer errors than doing it manually, as I have been.

I am trying to switch from a text box that pulls from a table created by a query to one that automatically calculates the information needed. Pulling from the query created table is not ideal due to possible status changes changing the way PTO is calculated. If someone changes from FT to PT (or vice versa), I need their allowed vacation amount to update automatically, rather than having to rerun the query to get it figured out.

This is what I have so far. Yes, I know the syntax I'm using is probably incorrect, but this was done using the nested IIf statements as a guide. And my VB book won't be here until sometime near the end of next week. (Yes, I am one of those who will purchase a manual just to complete one project)

Biggest problem at this point is I don't want PTOyear to have to be in a table somewhere - I'd like to just declare it at some point that PTOyear = 2010 (or 2011 next year, and so on...)

Expand|Select|Wrap|Line Numbers
  1. If Status.Employees="FT" Then
  2.     If PTOyear-Year(HireDate.Employees)>=20 Then
  3.         AlwdVac.Form1="160"
  4.     Else
  5.     If PTOyear-Year(HireDate.Employees)>=16 Then
  6.         AlwdVac.Form1=(PTOyear-Year(HireDate.Employees))*8
  7.     Else
  8.     IF PTOyear-Year(HireDate.Employees)>=5 Then
  9.         AlwdVac.Form1="120"
  10.     Else
  11.     IF PTOyear-Year(HireDate.Employees)>=2 Then
  12.         AlwdVac.Form1="80"
  13.     Else
  14.     If PTOyear-Year(HireDate.Employees)=1 Then
  15.         If 12-Month(HireDate.Employees)>2 Then
  16.             AlwdVac.Form1="64"
  17.         Else
  18.         AlwdVac.Form1="40"
  19.     Else
  20.     If 12-Month(HireDate.Employees)>2 Then
  21.         AlwdVac.Form1=ROUND((12-Month(HireDate.Employees))*2.67,0)
  22.     Else
  23.     AlwdVac.Form1="0"
  24. Else
  25. If Status.Employees="PT" Then
  26.     If PTOyear-Year(HireDate.Employees)>=20 Then
  27.         AlwdVac.Form1="100"
  28.     Else
  29.     If PTOyear-Year(HireDate.Employees)>=16 Then
  30.         AlwdVac.Form1=(PTOyear-Year(HireDate.Employees))*5
  31.     Else
  32.     IF PTOyear-Year(HireDate.Employees)>=5 Then
  33.         AlwdVac.Form1="75"
  34.     Else
  35.     IF PTOyear-Year(HireDate.Employees)>=2 Then
  36.         AlwdVac.Form1="50"
  37.     Else
  38.     If PTOyear-Year(HireDate.Employees)=1 Then
  39.         If 12-Month(HireDate.Employees)>2 Then
  40.             AlwdVac.Form1="40"
  41.         Else
  42.         AlwdVac.Form1="25"
  43.     Else
  44.     If 12-Month(HireDate.Employees)>2 Then
  45.         AlwdVac.Form1=ROUND((12-Month(HireDate.Employees))*1.67,0)
  46.     Else
  47.     AlwdVac.Form1="0"
  48. Else
  49. If Status.Employees="ARR" Then
  50.     AlwdVac.Form1="0"
  51. Else
  52. If Status.Employees="SAL" THen
  53.     AlwdVac.Form1=""
  54. 'This needs to be able to be entered manually, as the allowed vacation and personal for Salaried employees can vary
  55. Else
  56. AlwdVac.Form1="Status Needed"
Thanks in advance for any constructive help you can give me!
Dec 31 '09 #1
5 1651
Guido Geurs
767 Expert 512MB
dear,

Where are the "END IF" of the nested IF's?
Please, is it possible to write the code in stadges, it will be much better to understand for us.
like :
============
If .... then
if ... then
...
else
if... then
...
else
...
end if
end if
else
....
....
end if
=====================
br,
Jan 1 '10 #2
Guido Geurs
767 Expert 512MB
dear,

sorry but quick replay delete the leading spaces.

I resend the structure:


Expand|Select|Wrap|Line Numbers
  1. If .... then
  2.    if ... then
  3.       ...
  4.    else
  5.       if... then
  6.          ...
  7.       else
  8.          ...
  9.       end if
  10.    end if
  11. else
  12.    ....
  13.    ....
  14. end if

br,
Jan 1 '10 #3
Guido Geurs
767 Expert 512MB
dear,

I think i see a struckture and it will be better to use the "select case" instead of all these "if then else"s.

Is it like this?
Expand|Select|Wrap|Line Numbers
  1. Select Case Status.Employees
  2. Case "FT"
  3.    Select Case PTOyear - Year(HireDate.Employees)
  4.    Case Is >= 20
  5.       AlwdVac.Form1 = "160"
  6.    Case Is >= 16
  7.       AlwdVac.Form1 = (PTOyear - Year(HireDate.Employees)) * 8
  8.    Case Is >= 5
  9.       AlwdVac.Form1 = "120"
  10.    Case Is >= 2
  11.       AlwdVac.Form1 = "80"
  12.    Case 1
  13.       Select Case 12 - Month(HireDate.Employees)
  14.       Case Is > 2
  15.          AlwdVac.Form1 = "64"
  16.          '§ here i'm losing track: 2x "AlwdVac.Form1 =" ????
  17.          '§ 2x "If 12 - Month(HireDate.Employees) > 2 Then" ?????
  18.       End Select
  19.    End Select
  20. Case "PT"
  21.    Select Case PTOyear - Year(HireDate.Employees)
  22.    Case Is >= 20
  23.       AlwdVac.Form1 = "100"
  24.    Case Is >= 16
  25.       AlwdVac.Form1 = (PTOyear - Year(HireDate.Employees)) * 5
  26.    Case Is >= 5
  27.       AlwdVac.Form1 = "75"
  28.    Case Is >= 2
  29.       AlwdVac.Form1 = "50"
  30.    Case 1
  31.       Select Case 12 - Month(HireDate.Employees)
  32.       Case Is > 2
  33.          AlwdVac.Form1 = "64"
  34.          '§ here i'm losing track: 2x "AlwdVac.Form1 =" ????
  35.          '§ 2x "If 12 - Month(HireDate.Employees) > 2 Then" ?????
  36.       End Select
  37.    End Select
  38. Case "ARR"
  39.    AlwdVac.Form1 = "0"
  40. Case "SAL"
  41.    AlwdVac.Form1 = ""
  42. '........
  43.  
br,
Jan 1 '10 #4
I understand where and why you got lost. But if I understand your procedure correctly, the code for calculating personal time would be:

Expand|Select|Wrap|Line Numbers
  1. Select Case Status.Employees
  2. Case "FT"
  3.      AlwdPers.Form1="16"
  4. Case "PT"
  5.      AlwdPers.Form1="10"
  6. Case "ARR"
  7.      AlwdPers.Form1="0"
  8. Case "SAL"
  9.      AlwdPers.Form1=""
And completing what you started (ignoring PT since it's basically the same as FT) would be:
Expand|Select|Wrap|Line Numbers
  1. Select Case Status.Employees
  2. Case "FT"
  3.    Select Case PTOyear - Year(HireDate.Employees)
  4.    Case Is >= 20
  5.       AlwdVac.Form1 = "160"
  6.    Case Is >= 16
  7.       AlwdVac.Form1 = (PTOyear - Year(HireDate.Employees)) * 8
  8.    Case Is >= 5
  9.       AlwdVac.Form1 = "120"
  10.    Case Is >= 2
  11.       AlwdVac.Form1 = "80"
  12.    Case Is = 1
  13.       Select Case 12 - Month(HireDate.Employees)
  14.       Case Is > 2
  15.          AlwdVac.Form1 = "64"
  16.       Case Is <=2
  17.      AlwdVac.Form1= "40"
  18.       End Select
  19.    Case Is = 0
  20.       Select Case 12 - Month(HireDate.Employees)
  21.       Case Is > 2
  22.      AlwdVac.Form1 = ROUND((12-Month(HireDate.Employees))*2.67,0)
  23.       Case Is <= 2
  24.      AlwdVac.Form1 = "0"
  25.       End Select     
  26.    End Select
Which brings up two questions for me...
Do I have to "End Select" the original "Select Case Status.Employees"?

And how do I declare in there that PTOyear = 2010?

Thanks so much for your help!!
Jan 1 '10 #5
Guido Geurs
767 Expert 512MB
Dear,


Yes, Your structure seems to be working.

Q1 - Yes, a "Select Case" must always be closed with "End Select" like the "If" must always be closed with "End If".
The structure of "Select Case" is :

Expand|Select|Wrap|Line Numbers
  1. Select Case ...
  2.    Case x
  3.       ...
  4.    Case y
  5.       ...
  6.    Else Case  (if previous cases are not valid and there must be done something)
  7. End select
Q2 - There are 2 possibilities:
1- if PTOyear = 2010 must not change during the use of the program, set it in the code => PTOyear = 2010.
In this case, if it must change over the years, you must change it in the program and so compile it each time !!!.

I think it's better to set it on the form with a TextBox. (see option 2)

2- if the user must change it set it with a Textbox on the form.
Set it in the program with (if the Textbox name = Text_PTOYear):

PTOyear = Val(Text_PTOYear.Text)

br,
Jan 2 '10 #6

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

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
2
by: Jozef | last post by:
Hello, I am trying to put together a module and open a workspace on a database that has a simple password (using Access XP). This is the lin that I'm having trouble with; Set wrk =...
0
by: Jozef | last post by:
Hello, I'm having trouble with the download links on my web server. The error I'm getting is; CGI Timeout The specified CGI application exceeded the allowed time for processing. The server...
1
by: Jozef | last post by:
Hello. I'm having trouble creating a blank solution (and ASP.net web application) from my laptop. I own the server (in fact it's sitting right next to me) and have added the URL to the trusted...
1
by: MLH | last post by:
Am having trouble with the filter property setting below. Would like to filter the listing to car makes beginning with "D". I'm blowing it on the filter spec somehow??? Sub OpenRecordsetX() ...
3
by: Michael | last post by:
Hi all, I'm having trouble PInvoking a TCHAR within a struct. I'll paste the specific struct's API definition below. I've tried so many numerous variations. The main Win32 error I get is...
2
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my...
3
by: jaesik | last post by:
Hi all, I've been working on my personal portfolio website and been struggling a lot because of J-query. Since my j-query level is not like master.. I usually modify existing j-query plugins to...
1
by: Connor Bergman | last post by:
Im trying to create a bank statement basically, and Im having trouble formatting the output to a grid, from a .txt file. And I wrote the file, and can read the first line, and want to pull the date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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
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,...
0
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...

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.