473,785 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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 1674
Guido Geurs
767 Recognized Expert Contributor
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 Recognized Expert Contributor
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 Recognized Expert Contributor
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
Merdina
2 New Member
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.Employee s"?

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

Thanks so much for your help!!
Jan 1 '10 #5
Guido Geurs
767 Recognized Expert Contributor
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_PTOYea r.Text)

br,
Jan 2 '10 #6

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

Similar topics

1
2589
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 access the recordset it displays the results, what the real issue is that the entry is not made into the database even though i use the Update command and i have also tried the BeginTrans and CommitTrans nothign seems to work and i am unable to...
2
4549
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 = CreateWorkspace("TestWrkspc", "Admin", conDbPwd) conDBPwd is a variable that contains the password. There is no independant workgroup file, just the default. This is the error message I'm getting;
0
1540
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 has deleted the process. It's a fresh Windows 2000 server install, but I also installed the ASP.net
1
1637
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 sites on my laptop. Here are the details; This is what I'm selecting from the start page.... >Add New Blank Solution >Visual Basic Projects,
1
5148
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() Dim MyDB As Database Dim rstTemp As Recordset Dim rstTemp2 As Recordset Set MyDB = CurrentDb()
3
5743
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 0x3f0 / 515L which amounts to ERROR_NO_TOKEN. Every single instance of this in the past was due to mistakes I made while within PInvoked structs. Is anybody able to point me to documentation or just tell me outright how to
2
2028
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 office computer (under Linux), but I have to write some code for the system simulator for the Cell BE processor (the thing inside the PS3), which is apparently a PPC architecture, and I can't get the clock function to
3
1504
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 meet my needs and this time I'm trying to combine both accordion plugin and slideshow plugin. I used the tutorial for accordion from this website - http://acrisdesign.com/2010/03/jquery-tutorial-toggle-effect-on-hoverclick also used the...
1
1488
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 out, and seperate the amount. And with the following lines say the date, type of transaction, the location, amount of the transaction, and finally the running total. here is what I'm looking to achieve with this:(with all the numbers and columns...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.