473,608 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some problems with annual leave database

10 New Member
Hi, I need to create an annual leave Database for the company. I admit I was a complete novice at this. But I got thrown the job and I have to do it. So here's what I get so far, but I got pretty much stuck for some days figuring out what to do. Sorry I can't think of a better title.

I have a tblMainProfile table, which stores everything about employee's particulars. ID, name, NIRC, etc etc.

Next, I have tblLeaveEntitle ment table, which stores how many days of each type of leaves does each employee gets entitled to. Note that the same employee may get different number of entitled leaves each year. So I have, Index(auto-number, pkey), EmployeeID(text , can have a mix of letters and numbers), Year(number, to differentiate between each year's entitlement), LeaveType(Text, the different types of leaves, like Sick Leave, Vacation, etc), DaysEntitled(nu mber, contains the number of days of leaves entitled).

Then I have tblLeaveApply, which stores data for leave application. Here I have many fields, but those that are related to this problem - I have EmployeeID, LeaveType(combo box, get from tblLeaveEntitle ment.LeaveType) , Days(contains how many days is each leave application).

Here is what I currently have. Employee input employeeID and hit a button. A main form pops up, which contains data from tblMainProfile, 1 sub-form to show the leave entitlements belong to current user based on employeeID, and another form data source from tblLeaveApply for the application itself. Now when an employee applies for a leave, after they select their dates, the field Days will be auto calculated (no problem here). Then they select their LeaveType and so on.

What I need to do is to show the total number of days taken for that particular leave type, and how many days are left (aka Leave balance). I'm not sure if I should have a field in tblLeaveApply for DaysEntitled, or is having DaysEntitled in tblLeaveEntitle ment okay? I tried using a query to calculate total number of days taken and days left, but it just shows me everything in my tblLeaveEntitle ment. The dummy data I had was Vacation - 2 days. But it ended up showing me ALL types of leave with 2 days taken even though I don't have such data. This happens when I used both tblLeaveApply and tblLeaveEntitle ment tables in the query. Whenever I use just one table, it works fine. Except that I can't just use one table because tblLeaveApply doesn't have the field DaysEntitled.
Calculative fields in query is as follows:
Expand|Select|Wrap|Line Numbers
  1. TotalLeaveTaken: Days
  2. Sum
Expand|Select|Wrap|Line Numbers
  1. DaysLeft: DaysEntitled-TotalLeaveTaken
The possible solutions I can think of is (1) create a DaysEntitled field in tblLeaveApply so my query can just use tblLeaveApply only. But I can't make the form autofill up the value from tblLeaveEntitle d, based on whatever leave type the user chooses from combo box. I tried DLookup but it just tells me either data type mismatch, or no automated object. (2) somehow make the query works using 2 tables. I'm not really sure how to get this going.

tblLeaveApply and tblLeaveEntitle ment are both linked using EmployeeID, none are Pkey. tblMainProfile and tblLeaveApply are linked using EmployeeID too, with tblMainProfile' s employeeID being Pkey.

Thanks in advance. I been trying to make it work with much frustration. Any more data needed I would gladly provide. But as this is my first time, I'm not sure what information would be useful oand what would be not.
Aug 18 '08 #1
11 5566
hjozinovic
167 New Member
I would make a query based on tblLeaveEntitle ment and tblLeaveApply.
These two tables should be joined using EmployeeID and Year, and should be joined in order that query shows ALL EmployeeIDs and corresponding Years from tblLeaveEntitle ment and only those from tblLeaveApply where the fields EmployeeID and Year are equial.

Then make a subform based on that query and put it on MainProfile form connecting it via EmployeeID.
Aug 18 '08 #2
jjkeeper
10 New Member
Really appreciate your reply. So you mean I should have a Year field in tblLeaveApply which the user have to manually input in the current Year upon application of the leave? Is there a better way to do enter the value for the Year field here? I'm thinking of putting this under the Open Form event so it auto fills it with current year. Will it work?
Expand|Select|Wrap|Line Numbers
  1. Me.Year.Setfocus
  2. Me.Year.Value=Year(Date())
Because right now I only have Year field in tblLeaveEntitle ment. I admit I didn't think of that. I was just thinking of EmployeeID and LeaveType.

Another big problem is actually the calculation of the TotalDaysTaken and DaysLeft. I will post the SQL codes of my current query tomorrow when I'm at work (I don't have the database at home). Btw, it's 11.30pm now, just so you can estimate the time if you want to. But I get weird results whenever I try to create a query using two tables.
Aug 18 '08 #3
hjozinovic
167 New Member
Really appreciate your reply. So you mean I should have a Year field in tblLeaveApply which the user have to manually input in the current Year upon application of the leave? Is there a better way to do enter the value for the Year field here? I'm thinking of putting this under the Open Form event so it auto fills it with current year. Will it work?
I would not use Open form event for entering value into the Year field.
That way you would be changing that field whenever you open the form (even next year)
It would be better to do that in the AfterUpdate event of combo box listing LeaveType or something like that...
Expand|Select|Wrap|Line Numbers
  1. Me!Year=Year(Date())
To ansver other part of the question...yes, you should have Year field in your tblLeaveApply table in order to distinguish which Leave reffers to which year.
Aug 18 '08 #4
hjozinovic
167 New Member
After exmining this better, I would recommend you the following:

tblMainProfile
ProfileID (pk)
EmployeeID
Name
...


tblLeaveEntitle ment
LeaveID(pk)
LeaveType

tblLeaveApply
LaYear
LaLeaveID(fk)
LaProfileID(fk)
LaDaysEntitled
LaDaysUsed

These three tables are related using pk/fk

Now let's get to the business...
A) Create Query1 using all fields from tblMainProfile and tblLeaveEntitle ment
Do not join these two in order to get cartesian product (all leave types for every employee)
B) Create Query2 using tblLeaveApply and Query1
Join them using ProfileID and LeaveID
Note: for each connection right-click the link between fields and select type that says something like "Select all ProfileID from Query1 and only those from tblLeaveApply where join fields are equial"
Do the same for LeaveID link.
Make a new field in Query2 like DaysLeft: Nz(LaDaysEntitl ed,0)-Nz(LaDaysUsed,0 )
C) Make a subform based on Query2 and put it on MainProfile form connecting it using ProfileID
Aug 18 '08 #5
jjkeeper
10 New Member
Oh wow, thanks very much for putting in the effort and time! I'm in the office now, I'll go and try it out and post back later.

Edit: Just one question, currently my tblMainProfile' s Pkey is EmployeeID, and I link the different tables together using EmployeeID too, with tblMainProfile' s being Pkey and the other tables' EmployeeID being Fkey with respective index field being Pkey (LeaveID, etc). Is there something wrong with the way I did it? Because from what you said, I should be creating a ProfileID auto-number field to be Pkey, and linking using that instead of EmployeeID.
Aug 19 '08 #6
jjkeeper
10 New Member
okay, here's my query SQL codes. Here's what I need to get from the query. I need to show the LeaveType, DaysEntitled, EarnedLeave, TotalLeaveTaken and DaysLeft. I don't have DaysLeft in the query yet because I can't get TotalLeaveTaken to work.

In layman term, I need to show all Leave Entitled to EmployeeA in Year1, including the DaysEntitled, EarnedLeave,Day sLeft for each particular leave type. Whenever I include fields from tblLeaveApply, I get weird results like having multiple same records in the table.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblLeaveEntitlement.LegacyID, tblLeaveEntitlement.Year, tblLeaveEntitlement.LeaveType, tblLeaveEntitlement.DaysEntitled, Int(([DaysEntitled]/12)*Month(Date())) AS EarnedLeave, Sum(tblLeaveApply.Days) AS TotalLeaveTaken
  2. FROM tblLeaveEntitlement LEFT JOIN tblLeaveApply ON (tblLeaveEntitlement.LegacyID = tblLeaveApply.LegacyID) AND (tblLeaveEntitlement.Year = tblLeaveApply.LaYear)
  3. GROUP BY tblLeaveEntitlement.LegacyID, tblLeaveEntitlement.Year, tblLeaveEntitlement.LeaveType, tblLeaveEntitlement.DaysEntitled
  4. HAVING (((tblLeaveEntitlement.LegacyID)=[Forms]![frmLeaveApply]![tboLegacyID]) AND ((tblLeaveEntitlement.Year)=Year(Date())));
  5.  
EDIT: I figured it's probably due to the way I defined my LeaveType field in tblLeaveApply. Currently, I use a Lookup wizard to get the list of LeaveType from tblLeaveEntitle ment. The wizard creates this link
Expand|Select|Wrap|Line Numbers
  1. SELECT [tblLeaveEntitlement].[Index], [tblLeaveEntitlement].[LeaveType] FROM tblLeaveEntitlement; 
, auto renamed my LeaveType to Index and change the field type to Number. So I rename it back to LeaveType, change it back to Text. And change the codes to this instead
Expand|Select|Wrap|Line Numbers
  1. SELECT [tblLeaveEntitlement].[LeaveType] FROM tblLeaveEntitlement;
it works fine, I can select the correct list of LeaveTypes in the combo box, but when I try to make the query such that (with leaveType linked) show only those records that have the same data in linked field (just for testing), there're no records that are the same. Although upon manual comparison, there are "Vacation" in LeaveType fields in both tbl. So I'm thinking it's due to the way the LeaveType field is defined in tblLeaveApply. I want it to read from LeaveType field in tblLeaveEntitle ment. What's the right way to do it?
Aug 19 '08 #7
hjozinovic
167 New Member
Here is a sample database attached with what you want.
I believe design of your tables in the first place was not good.

Try looking at this and tell us if this is what you want
Attached Files
File Type: zip SampleDatabase.zip (73.7 KB, 575 views)
Aug 19 '08 #8
jjkeeper
10 New Member
Here is a sample database attached with what you want.
I believe design of your tables in the first place was not good.

Try looking at this and tell us if this is what you want
Many thanks. I'll take a look later, currently rushing a job to get it done before due. Thanks for the time and effort !!
Aug 20 '08 #9
jjkeeper
10 New Member
Yes, the idea is there, but for mine, i put the DaysEntitled into tblLeaveEntitle ment instead of tblLeaveApply. I managed to get it to display now though. There were some problems with the way my LeaveType field in tblLeaveApply was defined. Mostly due to the wizard, and then my own editing. Now my LeaveType fields in both tblLeaveApply and tblLeaveEntitle ment can properly sync and show me matching results.

So now i have this query.

shows all entitled leave if year is current, and status of leave application is not rejected. This query also calculates the TotalLeaveTaken and DaysLeft. This query is then used as a subform, linking with main form using EmployeeID.

The slight problem now is that, yes, it correctly shows all LeaveEntitlemen t based on year and employeeID. But, how do I make the query only calculate those days where the leave status is approved BUT show all records belong to the employee and current year? If I put in criteria for status to be "Approved", it only shows those records that have approved leave, and not all the different leave types for that employee and year.
Aug 20 '08 #10

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

Similar topics

0
2010
by: Constandinos Mavromoustakis | last post by:
Dear all, first we apologize if you receive multiple copies of this announcement. please see below if you are interested. Thank you in advance. ============================================================================ =
53
5685
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
0
2378
by: Constandinos Mavromoustakis | last post by:
http://agent.csd.auth.gr/~cmavrom -------------------------------------------------- ============================================================================ = 37th Annual Simulation Symposium April 18 - 22, 2004 Hyatt Regency Crystal City
2
1987
by: si.downes | last post by:
Using SQL Server 2000 SP3 I'm developing a data warehouse where data will be archived off to a filegroup, this filegroup backed up and the tables in this filegroup truncated to free up space on the server. So using Enterprise Manager I've copied data to the filegroup tables, backed up the file group, truncated the tables, but when I have restored the file group the database is stuck in a state of '(loading...)' and I can't get it to...
1
5494
by: Wayne | last post by:
I'm trying to save a report as a snapshot. If I use this code: DoCmd.OutputTo acOutputReport, "Snapshot Format (*.snp)", , False everything works fine, the file save dialogue box appears and the "Report's Name.snp" is entered as the file name to be saved and the file can be saved to the specified location. If however I try to give the report a different name by entering an object name like this:
193
9501
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
4
1463
by: JM | last post by:
Hi, I am an old programmer who is only just getting back into it after about 10 years, and for the life of me I can not work out what I am doing wrong. Firstly, I've recently downloaded and installed the very latest version of VB.NET Express & SQL Express. I have been slowly going through the suggested tutorial files on MSDN which after from the learnvisualstudio.net web site :
0
1291
by: RaiderXCChamp | last post by:
Hi! I am supposed to create a program that will display an investment schedule in a list box for my Visual Basics Class. 1. It says that annual interest is calculated using the simple interest formula: Interest = (Beginning Balance + Annual Investment) * Rate Assume the Investment Rate is entered and displayed as an annual rate. This formula also assumes the annual investment is made at the beginning of each year. 2. Include column...
4
1648
by: so many sites so little time | last post by:
ok so i am having problems if you look at the script below you will see that it the query has 4 values to insert but the actual values only contain title entry and now() for the date. well i have made the database and the blog_id is a primary auto interger what ever table bascly look below the the insert code block to find the code block that makes the table in the database, // Define the query. $query = "INSERT INTO blog_entries...
0
8063
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
8002
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
8496
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8148
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
8338
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...
0
6816
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6013
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
5475
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.