Help in access issue - calculated field for Leave system (1 Viewer)

dragony2000

New member
Local time
Today, 06:47
Joined
Aug 27, 2011
Messages
9
im working in leave system i have one problem in my access database

i want to sum all records content of field "days" and put it in only one specific calculated record in query or textbox in form and updated automatically every time when i make a new leave

so could u help me with vba or else and if there is anyone here can help me to finish this system because its first time for me to create leave system management for employees through access 2019
 

June7

AWF VIP
Local time
Today, 05:47
Joined
Mar 9, 2014
Messages
5,472
You want calculated data on form to refresh when new record is entered? Perhaps you should provide your db for analysis. Follow instructions at bottom of my post.
 

dragony2000

New member
Local time
Today, 06:47
Joined
Aug 27, 2011
Messages
9
i will send you the file after while and tell you exactly what i need because its complicated little bit
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:47
Joined
Jul 9, 2003
Messages
16,282
its first time for me to create leave system management for employees through access 2019
People new to MS Access often fall into the trap of creating an MS Access system that is like an Excel system. I strongly suggest that you post the database you have before you put any major effort into creating the forms, as you may need to change your table structures and hence the forms based on them will be invalid. This is such a common problem I have a whole blog devoted to it which you might find of interest:-

 

jdraw

Super Moderator
Staff member
Local time
Today, 09:47
Joined
Jan 23, 2006
Messages
15,379
dragony2000,
I recognize you are new to the forum and to database - welcome. We know little to nothing of you, your requirement, or your evolving database application. It is always better for communication if you provide some context for your question. As Uncle Gizmo suggested - we see many people who attempt to use "spreadsheet thinking" often unaware of database concepts.
I recommend that you give us a 30,000 ft overview of your requirement in simple English -avoid database jargon at this point. Provide some detail on the calculation that is the current issue and describe where it fits in the broad scheme of things.
 

dragony2000

New member
Local time
Today, 06:47
Joined
Aug 27, 2011
Messages
9
here is my database file, im sorry for bothering you but really i need hard help because i want to make some complicated work in this file and if you have better suggestion and good hints please provide me and also make it in database, now ill tell you details about that system:

** The important button in main screen that have the problem is " Leave System" button, all other buttons are ok.

1-I created a table "Contract Manpower" for employees.
2-We are making specific contract every 3 or 4 years so i created Table "Contract Period" for this matter, and this table is also important in my further calculations for the leave balance from starting till ending of contract.
3- I add "Holiday' Table manually, and every year i should add them so they deducted from upcoming leave days.
4-then i make query "Leave Details" this was created from "Leave Dates" Table and i put inside starting and ending dates and field for "days" this one should calculate between 2 dates and deduct fridays and holidays in the table when i choose the leave type "Annual" only, *** this is the 1st issue for me.

5- i make "leave balance" query that should have field called "balance" and this column should have remaining balance for each employee and should be updated when i print leave every time and also stored in the database so if i want to check remaining balance any time.
*** this is the 2nd issue for me.

** this hint for remaining balance im working under 4 years contract period. I want to calculate leave balance for each year regarding joining date till the end of contract. every year should give 30 days balance and divided into 1st year , 2nd year, 3rd year, 4th year. so if the 1st year become "0" automatically changed to 2nd year and so on .. so also i wanted to separate record like "Balance" you can put them together or give better solution.

6- I create "Leave System" Form have inside data for the employees , including 2 sub-forms "leave Details", "Leave Balance", i want to solve this issue that when i want to make new leave dates it should calculate the days and deducted from the only record in "Balance" sub-form or if you have better solution please provide in the database file. *** this is the 3rd issue for me.

7- after that i want to transfer data from printing button to send the data of employee and current leave detail from sub from to excel sheet. ** you can make any draft with any names and i can edit the code later.

im sorry for bothering you but im really stuck in this problem and as i said its first time to work in access.

and if you want any details tell me and ill follow you. thanks a lot everybody.
 

Attachments

  • Contract Employees.accdb
    1.4 MB · Views: 95

Eugene-LS

Registered User.
Local time
Today, 16:47
Joined
Dec 7, 2018
Messages
481
** The important button in main screen that have the problem is " Leave System" button, all other buttons are ok.
Code:
Private Sub cmdExitApp_Click() '!!! - Button name changed to "cmdExitApp"
    DoEvents
    DoCmd.Close acForm, Me.Name
    Application.Quit
End Sub
 

dragony2000

New member
Local time
Today, 06:47
Joined
Aug 27, 2011
Messages
9
Code:
Private Sub cmdExitApp_Click() '!!! - Button name changed to "cmdExitApp"
    DoEvents
    DoCmd.Close acForm, Me.Name
    Application.Quit
End Sub
thanks dear but this not what i mean im working on leave system management if you read my recent reply you will understand my problem.
 

Eugene-LS

Registered User.
Local time
Today, 16:47
Joined
Dec 7, 2018
Messages
481
thanks dear but this not what i mean im working on leave system management if you read my recent reply you will understand my problem.
I read your assignment.
Unfortunately, I don't have time to decide your whole list of wishes.
Have you thought about hiring a specialist to finish your application?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:47
Joined
Jul 9, 2003
Messages
16,282
I don't have time to decide your whole list of wishes.

I don't either!

Question...

How do you eat an Elephant?

Answer....

One bite at a time!

Question, where should I take my 1st bite?

Well, I wouldn't start with a tusk, too hard! Choose something easier, like have a nibble on an ear...

Another way of choosing the 1st bite, what part of your work flow gives you the most grief? Or what part of your work flow would benefit most from an MS Access management system?

So what's the first bite?
 

dragony2000

New member
Local time
Today, 06:47
Joined
Aug 27, 2011
Messages
9
I don't either!

Question...

How do you eat an Elephant?

Answer....

One bite at a time!

Question, where should I take my 1st bite?

Well, I wouldn't start with a tusk, too hard! Choose something easier, like have a nibble on an ear...

Another way of choosing the 1st bite, what part of your work flow gives you the most grief? Or what part of your work flow would benefit most from an MS Access management system?

So what's the first bite?
thanks for your reply, thats why i put all my thoughts so that anyone can help me.

and if i have specialist why i came here in the biggest forum of Access programmers Mr. Eugene-LS


I said if you have to ask me about something i will tell you directly and about starting of the program its about calculating days field in the query calculate excluding fridays and holidays

then second step to make single record for each employee that show remaining balance after making new leave
 

Eugene-LS

Registered User.
Local time
Today, 16:47
Joined
Dec 7, 2018
Messages
481
about calculating days field in the query calculate excluding fridays and holidays
Check this function please
Code:
Public Function GetDaysEFH(vDateStart, vDateEnd) As Integer ' v002
' Days between dates - "... EFH" = "Excluding Fridays And Holidays"
' https://www.access-programmers.co.uk/forums/threads/help-in-access-issue-calculated-field-for-leave-system.324595/#post-1842392
'---------------------------------------------------------------------------------------------------
'For tests:
'   ?GetDaysEFH ("01.01.2022", "15.01.2022") = 12  (15 - 2 (Frydays) -1 (Holiday "New Year"))
'---------------------------------------------------------------------------------------------------
Const iFirstDayOfWeek% = 2                 'vbMonday = 2; vbSunday = 1
'Holidays table
Const sTableHolidays$ = "Hoidays"          'Table name
Const sFldHolidaysStart$ = "[Holi Start]"  'Field name
Const sFldHolidaysQty$ = "Days"            'Field name
'Others:
Dim sVal$, iVal%, iDays%, iDaysLeft%, iDaysOff%, dDate As Date, vVal
'---------------------------------------------------------------------------------------------------
On Error GoTo GetDaysEFH_Err
  
    If IsDate(vDateStart) = False Then GoTo GetDaysEFH_End
    If IsDate(vDateEnd) = False Then GoTo GetDaysEFH_End
  
    iDays = DateDiff("d", vDateStart, vDateEnd)
    'Debug.Print "Total Days : " & iDays + 1
  
    For iVal = 0 To iDays
        dDate = DateAdd("d", iVal, vDateStart)
        iDaysLeft = iDays - iVal
     
        sVal = sFldHolidaysStart & " = " & Format$(dDate, "\#mm\/dd\/yyyy\#")
        vVal = DLookup(sFldHolidaysQty, sTableHolidays, sVal)
        If vVal > 0 Then
            If vVal > iDaysLeft Then vVal = iDaysLeft
            iDaysOff = iDaysOff + vVal
            iVal = iVal + vVal
            'Debug.Print "Holiday : " & dDate & _
                " Days: + " & vVal & " Total Days Off: " & iDaysOff
        Else
            If Weekday(dDate, iFirstDayOfWeek) = 5 Then
                iDaysOff = iDaysOff + 1
                'Debug.Print "Friday : " & dDate & _
                    " Days: + 1" & " Total Days Off: " & iDaysOff 'Friday
            End If
        End If
        'Debug.Print "dDate = " & dDate & _
            " - iDaysLeft = " & iDaysLeft & " Total Days Off: " & iDaysOff
     
    Next iVal
    GetDaysEFH = iDays + 1 - iDaysOff
GetDaysEFH_End:
    Exit Function

GetDaysEFH_Err:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Function : " & _
           "GetDaysEFH - DataTransform.", vbCritical, "Error!"
    'Debug.Print "GetDaysEFH_Line: " & Erl & "."
    Err.Clear
    Resume GetDaysEFH_End
End Function
 
Last edited:

mike60smart

Registered User.
Local time
Today, 14:47
Joined
Aug 6, 2017
Messages
1,905
thanks for your reply, thats why i put all my thoughts so that anyone can help me.

and if i have specialist why i came here in the biggest forum of Access programmers Mr. Eugene-LS


I said if you have to ask me about something i will tell you directly and about starting of the program its about calculating days field in the query calculate excluding fridays and holidays

then second step to make single record for each employee that show remaining balance after making new leave
How many days Leave is each Employee entitled to each year?
 

mike60smart

Registered User.
Local time
Today, 14:47
Joined
Aug 6, 2017
Messages
1,905
here is my database file, im sorry for bothering you but really i need hard help because i want to make some complicated work in this file and if you have better suggestion and good hints please provide me and also make it in database, now ill tell you details about that system:

** The important button in main screen that have the problem is " Leave System" button, all other buttons are ok.

1-I created a table "Contract Manpower" for employees.
2-We are making specific contract every 3 or 4 years so i created Table "Contract Period" for this matter, and this table is also important in my further calculations for the leave balance from starting till ending of contract.
3- I add "Holiday' Table manually, and every year i should add them so they deducted from upcoming leave days.
4-then i make query "Leave Details" this was created from "Leave Dates" Table and i put inside starting and ending dates and field for "days" this one should calculate between 2 dates and deduct fridays and holidays in the table when i choose the leave type "Annual" only, *** this is the 1st issue for me.

5- i make "leave balance" query that should have field called "balance" and this column should have remaining balance for each employee and should be updated when i print leave every time and also stored in the database so if i want to check remaining balance any time.
*** this is the 2nd issue for me.

** this hint for remaining balance im working under 4 years contract period. I want to calculate leave balance for each year regarding joining date till the end of contract. every year should give 30 days balance and divided into 1st year , 2nd year, 3rd year, 4th year. so if the 1st year become "0" automatically changed to 2nd year and so on .. so also i wanted to separate record like "Balance" you can put them together or give better solution.

6- I create "Leave System" Form have inside data for the employees , including 2 sub-forms "leave Details", "Leave Balance", i want to solve this issue that when i want to make new leave dates it should calculate the days and deducted from the only record in "Balance" sub-form or if you have better solution please provide in the database file. *** this is the 3rd issue for me.

7- after that i want to transfer data from printing button to send the data of employee and current leave detail from sub from to excel sheet. ** you can make any draft with any names and i can edit the code later.

im sorry for bothering you but im really stuck in this problem and as i said its first time to work in access.

and if you want any details tell me and ill follow you. thanks a lot everybody.
You say in your 1st Issue that you want to calculate days taken but not to include Fridays & Holidays when you select Annual Leave Type.
What do you want to calculate for any other Leave Types?
 

dragony2000

New member
Local time
Today, 06:47
Joined
Aug 27, 2011
Messages
9
You say in your 1st Issue that you want to calculate days taken but not to include Fridays & Holidays when you select Annual Leave Type.
What do you want to calculate for any other Leave Types?
thanks for your reply,

about first question its 30 days per year but also i want to make calculation for that regarding "Joining Date"
Like example the contract started 01-Jan-2020 the contract ends 31-DEC-2023 that means if there is employee joined 01-Jan-2023 it automatically calculated in Balance Record "30" and the next record show "from 1st Year"

if another employee joined 01-Jul-2021 it calculated automatically "15" and the next record show "from 2nd Year"

the problem is how to make this place updated not to be added new record. and only type "Annual" is required for calculation fridays and holidays.
 

dragony2000

New member
Local time
Today, 06:47
Joined
Aug 27, 2011
Messages
9
Thank you Mr Eugene

i will try this part but please i want to know where i should put this code: in the form or in the query ?? to make it works automatically when i work
 

Users who are viewing this thread

Top Bottom