Professional Documents
Culture Documents
' If not found in "Current Employee Data," search in "Old Master Data"
If empName = "Employee ID not found" Then
lastRow = wsOldMaster.Cells(wsOldMaster.Rows.Count, "B").End(xlUp).row
For i = 2 To lastRow
If wsOldMaster.Cells(i, 2).value = empID Then
empName = wsOldMaster.Cells(i, 5).value
Exit For
End If
Next i
End If
' If not found in "Current Employee Data," search in "Old Master Data"
If position = "NO DATA AVAILABLE" Then
lastRow = wsOldMaster.Cells(wsOldMaster.Rows.Count, "B").End(xlUp).row
For i = 2 To lastRow
If wsOldMaster.Cells(i, 2).value = empID Then
position = wsOldMaster.Cells(i, 12).value ' Assuming position is in Column L
Exit For
End If
Next i
End If
' If not found in "Current Employee Data," search in "Old Master Data"
If location = "NO DATA AVAILABLE" Then
lastRow = wsOldMaster.Cells(wsOldMaster.Rows.Count, "B").End(xlUp).row
For i = 2 To lastRow
If wsOldMaster.Cells(i, 2).value = empID Then
location = wsOldMaster.Cells(i, 11).value ' Assuming location is in Column K of "EmpProject"
Exit For
End If
Next i
End If
' If not found in "Current Employee Data," search in "Old Master Data"
If dateOfJoining = "Date not found" Then
lastRow = wsOldMaster.Cells(wsOldMaster.Rows.Count, 2).End(xlUp).row
For i = 2 To lastRow
If wsOldMaster.Cells(i, 2).value = empID Then
dateOfJoining = wsOldMaster.Cells(i, 8).value ' Assuming Date of Joining is in column H
Exit For
End If
Next i
End If
If IsEmpty(empTickets) Then
' If not found in "Current Employee Data," search in "Old Master Data" in column B
lastRow = wsOldMaster.Cells(wsOldMaster.Rows.Count, "B").End(xlUp).row
For i = 2 To lastRow
If wsOldMaster.Cells(i, 2).value = empID Then
empTickets = wsOldMaster.Cells(i, 18).value
Exit For
End If
Next i
End If
If IsEmpty(empTickets) Then
' Employee ID not found in either sheet, display a message
Me.FamilyTicketLabel.Caption = "Employee ID not found"
ElseIf empTickets = 1 Then
' Employee is not entitled to a family ticket
Me.FamilyTicketLabel.Caption = "Not entitled for Family Ticket"
ElseIf empTickets >= 3 And empTickets <= 4 Then
' Employee is entitled to 3 or 4 family tickets
Me.FamilyTicketLabel.Caption = empTickets
Else
' Employee is entitled to some other number of tickets
Me.FamilyTicketLabel.Caption = "Other entitlement (" & empTickets & ")"
End If
End Sub
Private Sub LeaveStartDateTextBox_AfterUpdate()
Dim strDate As String
Dim validDate As Date
Dim char As String
Dim i As Integer
Dim validChars As String
UpdateTotalDays
' Check if the conversion was successful and the date is valid
If IsDate(validDate) Then
' Format the date as DD/MMM/YYYY and update the TextBox
Me.LeaveStartDateTextBox.value = Format(validDate, "dd/mmm/yyyy")
Else
' Clear the TextBox and show a message if the date is invalid
Me.LeaveStartDateTextBox.value = ""
MsgBox "Invalid date format. Please use DD/MM/YYYY format.", vbExclamation, "Date Entry
Error"
End If
Else
' Clear the TextBox and show a message for invalid characters
Me.LeaveStartDateTextBox.value = ""
MsgBox "Invalid characters. Please use only numbers, hyphens, and slashes.", vbExclamation,
"Date Entry Error"
End If
End If
End Sub
' Check if the conversion was successful and the date is valid
If IsDate(validDate) Then
' Format the date as DD/MMM/YYYY and update the TextBox
Me.LeaveEndDateTextBox.value = Format(validDate, "dd/mmm/yyyy")
Else
' Clear the TextBox and show a message if the date is invalid
Me.LeaveEndDateTextBox.value = ""
MsgBox "Invalid date format. Please use DD/MM/YYYY format.", vbExclamation, "Date Entry
Error"
End If
Else
' Clear the TextBox and show a message for invalid characters
Me.LeaveEndDateTextBox.value = ""
MsgBox "Invalid characters. Please use only numbers, hyphens, and slashes.", vbExclamation,
"Date Entry Error"
End If
End If
End Sub
' Check if the conversion was successful and the date is valid
If IsDate(validDate) Then
' Format the date as DD/MMM/YYYY and update the TextBox
Me.DepartureDateTextBox.value = Format(validDate, "dd/mmm/yyyy")
Else
' Clear the TextBox and show a message if the date is invalid
Me.DepartureDateTextBox.value = ""
MsgBox "Invalid date format. Please use DD/MM/YYYY format.", vbExclamation, "Date Entry
Error"
End If
Else
' Clear the TextBox and show a message for invalid characters
Me.DepartureDateTextBox.value = ""
MsgBox "Invalid characters. Please use only numbers, hyphens, and slashes.", vbExclamation,
"Date Entry Error"
End If
End If
End Sub
Private Sub RequestDateTextBox_Enter()
' Check if the TextBox contains the hint text, and if so, clear it
If Me.RequestDateTextBox.value = "DD/MM/YYYY" Then
Me.RequestDateTextBox.value = ""
Me.RequestDateTextBox.ForeColor = RGB(0, 0, 0) ' Set text color to black
End If
End Sub
' Check if the conversion was successful and the date is valid
If IsDate(validDate) Then
' Format the date as DD/MMM/YYYY and update the TextBox
Me.RequestDateTextBox.value = Format(validDate, "dd/mmm/yyyy")
Else
' Clear the TextBox and show a message if the date is invalid
Me.RequestDateTextBox.value = ""
MsgBox "Invalid date format. Please use DD/MM/YYYY format.", vbExclamation, "Date Entry
Error"
End If
Else
' Clear the TextBox and show a message for invalid characters
Me.RequestDateTextBox.value = ""
MsgBox "Invalid characters. Please use only numbers, hyphens, and slashes.", vbExclamation,
"Date Entry Error"
End If
End If
End Sub
' Check if the conversion was successful and the date is valid
If IsDate(validDate) Then
' Format the date as DD/MMM/YYYY and update the TextBox
Me.JoiningDateTextBox.value = Format(validDate, "dd/mmm/yyyy")
Else
' Clear the TextBox and show a message if the date is invalid
Me.JoiningDateTextBox.value = ""
MsgBox "Invalid date format. Please use DD/MM/YYYY format.", vbExclamation, "Date Entry
Error"
End If
Else
' Clear the TextBox and show a message for invalid characters
Me.JoiningDateTextBox.value = ""
MsgBox "Invalid characters. Please use only numbers, hyphens, and slashes.", vbExclamation,
"Date Entry Error"
End If
End If
End Sub
' Define the range of values in column A (from A2 to the last used row)
Dim rangeValues As Range
Set rangeValues = ws.Range("A2:A" & lastRow)
' Define the range of values in column C (from C2 to the last used row)
Set rangeValues = ws.Range("C2:C" & lastRow)
' Initialize the FamilyTicketUtlzComboBox with data from the "Setting" worksheet
Dim wsSetting As Worksheet
Set wsSetting = ThisWorkbook.Worksheets("Setting")
End Sub
Private Sub UpdateTotalDays()
Dim startDate As Date
Dim endDate As Date
Dim totalDays As Integer
' Calculate the total days, and add 1 to include the end date
totalDays = DateDiff("d", startDate, endDate) + 1
Sub InitializeListViewColumns()
' Initialize the ListView control with columns
With Me.DataShowListView
' Clear any existing columns
.ColumnHeaders.Clear
' Add columns to the ListView based on the new order of headings
.ColumnHeaders.Add , , "Serial Number", 50 ' Add a column for serial number
.ColumnHeaders.Add , , "Employee ID", 70
.ColumnHeaders.Add , , "Employee Name", 200
.ColumnHeaders.Add , , "Company Joining Date", 100
.ColumnHeaders.Add , , "Position", 100
.ColumnHeaders.Add , , "Location", 100
.ColumnHeaders.Add , , "Leave Type", 100
.ColumnHeaders.Add , , "Leave Start Date", 100
.ColumnHeaders.Add , , "Leave End Date", 100
.ColumnHeaders.Add , , "Departure Date", 100
.ColumnHeaders.Add , , "Request Date", 100
.ColumnHeaders.Add , , "Total Days", 100
.ColumnHeaders.Add , , "Leave Balance", 100
.ColumnHeaders.Add , , "Joining Date", 100
.ColumnHeaders.Add , , "Paid Leave Days", 100
.ColumnHeaders.Add , , "Unpaid Leave Days", 100
.ColumnHeaders.Add , , "Leaves Expiring Next Year", 150
.ColumnHeaders.Add , , "Tickets Remaining", 100
.ColumnHeaders.Add , , "Ticket Remaining Years", 150
.ColumnHeaders.Add , , "Ticket Utilization Year", 100
.ColumnHeaders.Add , , "Family Ticket", 100
.ColumnHeaders.Add , , "Family Ticket Utilization", 100
.ColumnHeaders.Add , , "Remarks", 150
' Loop through the rows in the worksheet and add data to the ListView
For i = 2 To lastRow ' Assuming the first row contains headers
If ws.Cells(i, 2).value = empID Then
' Add an item to the ListView and increment the serial number
Set lvItem = Me.DataShowListView.ListItems.Add(, , serialNumber) ' Serial Number
serialNumber = serialNumber + 1 ' Increment the serial number
lvItem.ListSubItems.Add , , ws.Cells(i, 2).value ' Employee ID
lvItem.ListSubItems.Add , , ws.Cells(i, 3).value ' Employee Name
lvItem.ListSubItems.Add , , ws.Cells(i, 4).value ' Company Joining Date
lvItem.ListSubItems.Add , , ws.Cells(i, 5).value ' Position
lvItem.ListSubItems.Add , , ws.Cells(i, 6).value ' Location
lvItem.ListSubItems.Add , , ws.Cells(i, 7).value ' Leave Type
lvItem.ListSubItems.Add , , ws.Cells(i, 8).value ' Leave Start Date
lvItem.ListSubItems.Add , , ws.Cells(i, 9).value ' Leave End Date
lvItem.ListSubItems.Add , , ws.Cells(i, 10).value ' Departure Date
lvItem.ListSubItems.Add , , ws.Cells(i, 11).value ' Request Date
lvItem.ListSubItems.Add , , ws.Cells(i, 12).value ' Total Days
lvItem.ListSubItems.Add , , ws.Cells(i, 13).value ' Leave Balance
lvItem.ListSubItems.Add , , ws.Cells(i, 14).value ' Joining Date
lvItem.ListSubItems.Add , , ws.Cells(i, 15).value ' Paid Leave Days
lvItem.ListSubItems.Add , , ws.Cells(i, 16).value ' Unpaid Leave Days
lvItem.ListSubItems.Add , , ws.Cells(i, 17).value ' Leaves Expiring Next Year
lvItem.ListSubItems.Add , , ws.Cells(i, 18).value ' Total Tickets Remaining
lvItem.ListSubItems.Add , , ws.Cells(i, 19).value ' Tickets Remaining (Years)
lvItem.ListSubItems.Add , , ws.Cells(i, 20).value ' Ticket Utilization Year
lvItem.ListSubItems.Add , , ws.Cells(i, 21).value ' Family Ticket
lvItem.ListSubItems.Add , , ws.Cells(i, 22).value ' Family Ticket Utilization
lvItem.ListSubItems.Add , , ws.Cells(i, 23).value ' Remarks
End If
Next i
End Sub
' Set the worksheet where you want to save the data
Set ws = ThisWorkbook.Worksheets("Leave & Ticket Request Log")
' Update the "Srl #" column with the new value
ws.Cells(lastRow, 1).value = srlNumber
' Get the values from the form controls and save them in the respective columns
ws.Cells(lastRow, 2).value = Me.EmployeeIDTextBox.value
ws.Cells(lastRow, 3).value = Me.EmployeeNameLabel.Caption
ws.Cells(lastRow, 4).value = Me.DateOfJoiningLabel.Caption
ws.Cells(lastRow, 5).value = Me.PositionLabel.Caption
ws.Cells(lastRow, 6).value = Me.LocationLabel.Caption
ws.Cells(lastRow, 7).value = Me.LeaveTypeComboBox.value
ws.Cells(lastRow, 8).value = Me.LeaveStartDateTextBox.value
ws.Cells(lastRow, 9).value = Me.LeaveEndDateTextBox.value
ws.Cells(lastRow, 10).value = Me.DepartureDateTextBox.value
ws.Cells(lastRow, 11).value = Me.RequestDateTextBox.value
' Extract and save the numeric value for "Total Days"
Dim totalDaysValue As String
totalDaysValue = Me.TotalDaysLabel.Caption
totalDaysValue = Replace(totalDaysValue, "Total Days:", "") ' Remove the "Total Days:" text
ws.Cells(lastRow, 12).value = Val(totalDaysValue) ' Convert to numeric and save
' Extract and save the numeric value for "Leave Balance"
Dim leaveBalanceValue As String
leaveBalanceValue = Me.LeaveBalanceLabel.Caption
leaveBalanceValue = Replace(leaveBalanceValue, "Total Days:", "") ' Remove the "Total Days:" text
ws.Cells(lastRow, 13).value = Val(leaveBalanceValue) ' Convert to numeric and save
' Extract and save the numeric value for "Paid Leave Days"
Dim paidLeavesValue As String
paidLeavesValue = Me.PaidLeavesLabel.Caption
paidLeavesValue = Replace(paidLeavesValue, "Total Days:", "") ' Remove the "Total Days:" text
ws.Cells(lastRow, 15).value = Val(paidLeavesValue) ' Convert to numeric and save
' Extract and save the numeric value for "Unpaid Leave Days"
Dim unpaidLeavesValue As String
unpaidLeavesValue = Me.UnpaidLeavesLabel.Caption
unpaidLeavesValue = Replace(unpaidLeavesValue, "Total Days:", "") ' Remove the "Total Days:" text
ws.Cells(lastRow, 16).value = Val(unpaidLeavesValue) ' Convert to numeric and save
' Extract and save the numeric value for "Leaves Expiring Next Year"
Dim leavesExpiringValue As String
leavesExpiringValue = Me.LeavesExpiringLabel.Caption
leavesExpiringValue = Replace(leavesExpiringValue, "Total Days:", "") ' Remove the "Total Days:" text
ws.Cells(lastRow, 17).value = Val(leavesExpiringValue) ' Convert to numeric and save
' Inform the user that the data has been saved
MsgBox "Data has been successfully saved.", vbInformation, "Data Saved"
End Sub
End Sub
' Set the ranges for "Current Employee Data" and "Old Master Data" sheets
' Assuming "EmpID" is in column A of "Current Employee Data"
' and "EmpID (formula)" is in column B of "Old Master Data"
Set currentDataRange = ThisWorkbook.Sheets("Current Employee Data").Range("A:A")
Set oldDataRange = ThisWorkbook.Sheets("Old Master Data").Range("B:B")
' Check if the employee is found in the "Current Employee Data" range
For Each cell In currentDataRange
If cell.value = employeeID Then
StatusLabel.Caption = "ACTIVE"
StatusLabel.ForeColor = RGB(0, 128, 0) ' Green color
found = True
Exit For
End If
Next cell
' If not found in "Current Employee Data," check "Old Master Data" range
If Not found Then
For Each cell In oldDataRange
If cell.value = employeeID Then
StatusLabel.Caption = "RESIGNED"
StatusLabel.ForeColor = RGB(255, 0, 0) ' Red color
found = True
Exit For
End If
Next cell
End If
' If not found in either, keep the default "NO DATA AVAILABLE" status in black color
If Not found Then
StatusLabel.Caption = "NO DATA AVAILABLE"
StatusLabel.ForeColor = RGB(0, 0, 0) ' Black color
End If
End Sub