Agent not processing completely some times

Hello all,

I was wondering if someone could help me. I have an agent that I call from a submit action on the form. This agent does not always walk through all the steps in it. There is no consistency on what is does or does not skip in the agent. Some times it skips updating the profile document and the other day it skipped adding only one name to an email that is produced.

I have looked and there was no backup running at that time. There were no messages in the Domino Log nor in the montioring results.

Now we do have two buildings that are connected via wireless radios and I am not sure that it is not the issue. We have had a person use the same document from a computer in Portland, OR (the server is located in Louisville, KY) and the agent did not run at all.

Here is the agent …

Option Public

Option Declare

Dim CReason As String

Dim temp As String

Dim temp1 As String

Dim NumProcessed As Integer

Dim timesheet As NotesDocument

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Dim sdoc As NotesDocument

Dim key As String

Dim agent As NotesAgent

Dim tKey As String

Dim docForm As String

Dim HitNote As Integer

Dim b As Integer

Dim collection As NotesDocumentCollection

Dim rtitem As NotesRichTextItem

Sub Initialize

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Set uidoc = workspace.CurrentDocument

uidoc.EditMode = True

Call uidoc.Save

key = uidoc.FieldGetText(Cstr("EmployeeNumber"))

CReason = uidoc.FieldGetText("ChangeReason")



Dim newplant As String

newplant = uidoc.FieldGetText("NewPlant")



Dim plant As String 



Set db = session.CurrentDatabase

Set view = db.GetView("CILV")

Set doc = view.GetDocumentByKey(key)

Set collection = view.GetAllDocumentsByKey(key, True)



' Set the Author field in the 789 line document ... they were listed as editors of the db, I am now going to set them as authors and see if that makes a 

' difference

' Call uidoc.FieldSetText("Author", "[Admin]" &  "[HR]" & "[Payroll]" & "[Timesheets]")



While (key = doc.EmployeeNumber(0))

	docForm = doc.Form(0)

	Select Case CReason

	Case "Transfer"

		Call doc.ReplaceItemValue("Department", uidoc.FieldGetText("NewDepartment"))

		If newplant = "Preston" Then

			Call doc.ReplaceItemValue("Plant", "P")

		Elseif newplant = "Oaklawn" Then

			Call doc.ReplaceItemValue("Plant", "O")

		Elseif newplant = "Indiana" Then

			Call doc.ReplaceItemValue("Plant", "I")

		End If

		Call doc.ReplaceItemValue("Classification", uidoc.FieldGetText("NewClassification"))

		Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

		Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

		' Call a sub that sets the fields deptnum, workdays, shift, and supervisor.... 

		Call ChangeInfo(doc, uidoc)

		

	Case "Quit"

		If docForm = "Timesheet" Then

			Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			' Call a sub that sets the time on the timsheet, calculates the time, and then submits the timesheet

			Call ProcessTimesheet(doc, uidoc)

		Elseif docForm = "Profile Doc" Then

			Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			Call doc.ReplaceItemValue("TermDate", Datevalue(Today()))

		Else

		End If

		

		

	Case "Layoff"

		Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

		Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

		Call doc.ReplaceItemValue("TermDate", Datevalue(Today()))

		

		

	Case "Terminated"

		If docForm = "Timesheet" Then

			Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

				' Call a sub that sets the time on the timsheet, calculates the time, and then submits the timesheet

			Call ProcessTimesheet(doc, uidoc)

		Elseif docForm = "Profile Doc" Then

			Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			Call doc.ReplaceItemValue("TermDate", Datevalue(Today()))

		Else

		End If

		

	Case "Reinstated"

		' Edit the profile document bv deleting the term date and making the neccessary changes then create a Timesheet

		If docForm = "Timesheet" Then

			Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

		Elseif docForm = "Profile Doc" Then

			Call doc.ReplaceItemValue("Department", uidoc.FieldGetText("Department"))

			If plant = "Preston" Then

				Call doc.ReplaceItemValue("Plant", "P")

			Elseif plant = "Oaklawn" Then

				Call doc.ReplaceItemValue("Plant", "O")

			Elseif plant = "Indiana" Then

				Call doc.ReplaceItemValue("Plant", "I")

			End If

			Call doc.ReplaceItemValue("Classification", uidoc.FieldGetText("Classification"))

			Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			Call doc.ReplaceItemValue("TermDate", "")

			Call doc.ReplaceItemValue("AnnDate", uidoc.FieldGetText("Date"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			'  Call a sub to set the deptmun, supervisor, and shift and then create a timesheet

			Call Reinstated(doc, uidoc)

		Else

		End If

		

		

		

	Case "No Show"

		'Call uidoc.FieldSetText("EmployeeNumber", "999" + key)

		If docForm = "Timesheet" Then

			Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			'Call doc.ReplaceItemValue("EmployeeNumber", "999" + key)

			Call NoShow(doc, uidoc)

		Elseif docForm = "Profile Doc" Then

			Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

			Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			Call doc.ReplaceItemValue("NoShow", "No Show")

			'Call doc.ReplaceItemValue("TermDate", Datevalue(Today()))

			'Call doc.ReplaceItemValue("EmployeeNumber", "999" + key)

		Else

		End If

		

		

	Case "New Hire"

		'  Need to do a lookup to see if the Employee has a term date.  If they do then the person has worked here before 

		' and I need to complete the same tasks as if the person were reinstated

		If Not Isnull(doc.TermDate)Then

			If (docForm = "Profile Doc")  Then

				Call doc.ReplaceItemValue("Department", uidoc.FieldGetText("Department"))

				If plant = "Preston" Then

					Call doc.ReplaceItemValue("Plant", "P")

				Elseif plant = "Oaklawn" Then

					Call doc.ReplaceItemValue("Plant", "O")

				Elseif plant = "Indiana" Then

					Call doc.ReplaceItemValue("Plant", "I")

				End If

				Call doc.ReplaceItemValue("Classification", uidoc.FieldGetText("Classification"))

				Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

				Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

				Call doc.ReplaceItemValue("TermDate", "")

				Call doc.ReplaceItemValue("SystemAnnDate", doc.GetFirstItem("AnnDate"))

				Call doc.ReplaceItemValue("AnnDate", uidoc.FieldGetText("Date"))

				Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

				Call doc.ReplaceItemValue("NoShow", "")

			'  Call a sub to set the deptmun, supervisor, and shift and then create a timesheet

				Call Reinstated(doc, uidoc)

			Elseif docForm = "Timesheet" Then

				Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

				Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			End If

		Elseif Isnull(doc.TermDate) Then

			If (docForm = "Profile Doc")  Then

				Call doc.ReplaceItemValue("Department", uidoc.FieldGetText("Department"))

				If plant = "Preston" Then

					Call doc.ReplaceItemValue("Plant", "P")

				Elseif plant = "Oaklawn" Then

					Call doc.ReplaceItemValue("Plant", "O")

				Elseif plant = "Indiana" Then

					Call doc.ReplaceItemValue("Plant", "I")

				End If

				Call doc.ReplaceItemValue("Classification", uidoc.FieldGetText("Classification"))

				Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

				Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

				Call doc.ReplaceItemValue("TermDate", "")

				Call doc.ReplaceItemValue("AnnDate", uidoc.FieldGetText("Date"))

				Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

				Call doc.ReplaceItemValue("NoShow", "")

			Elseif docForm = "Timesheet" Then

				Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

				Call doc.ReplaceItemValue("ESDate", Datevalue(Today()))

			End If

		Else

		End If

		

		

	Case "Change of Job Status"

		Call doc.ReplaceItemValue("Department", uidoc.FieldGetText("NewDepartment"))

		If newplant = "Preston" Then

			Call doc.ReplaceItemValue("Plant", "P")

		Elseif newplant = "Oaklawn" Then

			Call doc.ReplaceItemValue("Plant", "O")

		Elseif newplant = "Indiana" Then

			Call doc.ReplaceItemValue("Plant", "I")

		End If

		Call doc.ReplaceItemValue("Classification", uidoc.FieldGetText("NewClassification"))

		Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

		Call doc.ReplaceItemValue("ESDate", Today())

				' Call a sub that sets the fields deptnum, workdays, shift, and supervisor.... 

		Call ChangeInfo(doc, uidoc)

	Case "Group Lead"

		Call doc.ReplaceItemValue("EmploymentStatus", uidoc.FieldGetText("ChangeReason"))

		Call doc.ReplaceItemValue("ESDate", Today())

	Case Else

		Exit Sub

	End Select

	Call doc.ComputeWithForm(True, False)

	Call doc.Save(False,True)

	Set doc = view.GetNextDocument(doc)	

Wend



' call a sub that creates the emil

Call Email(doc, uidoc)



' call a sub that refreshs the department views

Call RefreshDept(doc, uidoc)





Call uidoc.FieldSetText("DateSubmitted", Cstr(Now()))

Call uidoc.Save

uidoc.Close

'If uidoc.ChangeReason = "New Hire" Then

'	Set sdoc = New NotesDocument (db)

'	sdoc.Form = "DC Shift Info"

'Elseif uidoc.ChangeReason = "Reinstated"  Then

	' need to find the document that belongs to the employe

'Else

	'End If

End Sub

Sub ChangeInfo (doc As NotesDocument, uidoc As NotesUIDocument)

Dim deptview As NotesView

Dim deptview1 As NotesView 

Dim deptview2 As NotesView

Set deptview = db.GetView("DSet")

Set deptview1 = db.GetView("DTL")

Set deptview2 = db.GetView("DAD")

temp = uidoc.FieldGetText("NewDepartment") + " - " + uidoc.FieldGetText("NewPlant")	

Select Case temp

Case "1WD 4x10 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Sturgeon, Becky")

Case "1WD 4x10 Extrusion - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 21)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Adkins, David")	

Case "1WD 4x10 Extrusion - Preston"

	Call doc.ReplaceItemValue("DeptNum", 11)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Goff, Rick")	

Case "1WD 4x10 Fabrication - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 39)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Holmes, Dennis")

Case "1WD 4x10 Maint  - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 29)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Stamm, David")

Case "1WD 4x10 Paintline - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 38)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Lindsey, Scott")

Case "1WD 4x10 Polishing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 27)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Slater, Mike")

Case "1WD 4x10 QA Crew - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 32)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Willbanks, Lorna")

Case "1WD 4x10 QA Dock - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 34)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Napier, Steve")

Case "1WD 4x10 QA Dock - Preston"

	Call doc.ReplaceItemValue("DeptNum", 36)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Peppers, Pam")

Case "1WD 5x8 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Sturgeon, Becky")

Case "1WD 5x8 D/M - Indiana"

	Call doc.ReplaceItemValue("DeptNum", 9)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Meier, Kenny")

Case "1WD 5x8 Janitor - Preston"

	Call doc.ReplaceItemValue("DeptNum", 10)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Beckner, Ron")

Case "1WD 5x8 Janitor - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 20)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Stamm, David")

Case "1WD 5x8 Maint - Preston"

	Call doc.ReplaceItemValue("DeptNum", 7)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Beckner, Ron")

Case "1WD 5x8 Paintroom - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 28)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Lindsey, Scott")

Case "1WD 5x8 QA Crew - Preston"

	Call doc.ReplaceItemValue("DeptNum", 31)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Peppers, Pam")

Case "1WE 3x12 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Wernert, Glen")

Case "1WE 3x12 Extrusion - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 21)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Mayes, Jimmy")

Case "1WE 3x12 Fabrication - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 39)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Greenwell, Rod")

Case "1WE 3x12 Maint - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 29)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Stamm, David")

Case "1WE 3x12 Paintline - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 38)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Lindsey, Scott")

Case "1WE 3x12 Polishing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 27)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Wernert, Glen")

Case "1WE 3x12 QA Crew - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 32)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Silver, Dee")

Case "2WD 4x10 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Hall, Doug")

Case "2WD 4x10 Extrusion - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 21)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Adkins, David")

Case "2WD 4x10 Fabrication - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 39)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Holmes, Dennis")

Case "2WD 4x10 Maint - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 29)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Schedko, Billy")

Case "2WD 4x10 Paintline - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 38)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Lindsey, Scott")

Case "2WD 4x10 Paintroom - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 28)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Lindsey, Scott")

Case "2WD 4x10 Polishing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 27)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Check, Kenny")

Case "2WD 4x10 QA Crew - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 32)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Dean, Paula")

Case "2WD 4x10 QA Dock - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 34)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Dean, Paula")

Case "2WE 3x12 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Wernert, Glen")

Case "2WE 3x12 Extrusion - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 21)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Priser, Steve")	

Case "2WE 3x12 Fabrication - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 39)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Greenwell, Tracy")	

Case "2WE 3x12 Maint - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 29)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Stamm, David")	

Case "2WE 3x12 Polishing  - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 27)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Wernert, Glen")	

Case "2WE 3x12 QA Crew  - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 32)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Silver, Dee")	

End Select

Call deptview1.Refresh

Call deptview2.Refresh

Call deptview.Refresh

Call deptview2.Refresh

Call deptview.Refresh

End Sub

Sub Reinstated(doc As NotesDocument, uidoc As NotesUIDocument)

Dim docForm As String

docForm = doc.Form(0)

temp = uidoc.FieldGetText("Department") + " - " + uidoc.FieldGetText("Plant")

Select Case temp

Case "1WD 4x10 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Sturgeon, Becky")

Case "1WD 4x10 Extrusion - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 21)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Adkins, David")	

Case "1WD 4x10 Extrusion - Preston"

	Call doc.ReplaceItemValue("DeptNum", 11)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Goff, Rick")	

Case "1WD 4x10 Fabrication - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 39)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Holmes, Dennis")

Case "1WD 4x10 Maint  - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 29)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Stamm, David")

Case "1WD 4x10 Paintline - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 38)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Lindsey, Scott")

Case "1WD 4x10 Polishing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 27)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Slater, Mike")

Case "1WD 4x10 QA Crew - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 32)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Willbanks, Lorna")

Case "1WD 4x10 QA Dock - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 34)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Napier, Steve")

Case "1WD 4x10 QA Dock - Preston"

	Call doc.ReplaceItemValue("DeptNum", 36)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Peppers, Pam")

Case "1WD 5x8 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Sturgeon, Becky")

Case "1WD 5x8 D/M - Indiana"

	Call doc.ReplaceItemValue("DeptNum", 9)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Meier, Kenny")

Case "1WD 5x8 Janitor - Preston"

	Call doc.ReplaceItemValue("DeptNum", 10)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Beckner, Ron")

Case "1WD 5x8 Janitor - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 20)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Stamm, David")

Case "1WD 5x8 Maint - Preston"

	Call doc.ReplaceItemValue("DeptNum", 7)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Beckner, Ron")

Case "1WD 5x8 Paintroom - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 28)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Lindsey, Scott")

Case "1WD 5x8 QA Crew - Preston"

	Call doc.ReplaceItemValue("DeptNum", 31)

	Call doc.ReplaceItemValue("WorkDays", 5)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Peppers, Pam")

Case "1WE 3x12 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Wernert, Glen")

Case "1WE 3x12 Extrusion - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 21)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Mayes, Jimmy")

Case "1WE 3x12 Fabrication - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 39)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Greenwell, Rod")

Case "1WE 3x12 Maint - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 29)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Stamm, David")

Case "1WE 3x12 Paintline - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 38)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Lindsey, Scott")

Case "1WE 3x12 Polishing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 27)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Wernert, Glen")

Case "1WE 3x12 QA Crew - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 32)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 1)

	Call doc.ReplaceItemValue("Supervisor", "Silver, Dee")

Case "2WD 4x10 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Hall, Doug")

Case "2WD 4x10 Extrusion - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 21)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Adkins, David")

Case "2WD 4x10 Fabrication - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 39)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Holmes, Dennis")

Case "2WD 4x10 Maint - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 29)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Schedko, Billy")

Case "2WD 4x10 Paintline - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 28)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Dever, Doris")

Case "2WD 4x10 Polishing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 27)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Check, Kenny")

Case "2WD 4x10 QA Crew - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 32)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Dean, Paula")

Case "2WD 4x10 QA Dock - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 34)

	Call doc.ReplaceItemValue("WorkDays", 4)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Dean, Paula")

Case "2WE 3x12 Anodizing - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 25)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Wernert, Glen")

Case "2WE 3x12  Extrusion - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 21)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Priser, Steve")	

Case "2WE 3x12  Fabrication - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 39)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Greenwell, Tracy")	

Case "2WE 3x12  Maint - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 29)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Stamm, David")	

Case "2WE 3x12 Polishing  - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 27)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Wernert, Glen")	

Case "2WE 3x12 QA Crew  - Oaklawn"

	Call doc.ReplaceItemValue("DeptNum", 32)

	Call doc.ReplaceItemValue("WorkDays", 3)

	Call doc.ReplaceItemValue("Shift", 2)

	Call doc.ReplaceItemValue("Supervisor", "Silver, Dee")	

End Select



' call a sub that populates the days that are before the start date in the timesheet so the supervisor does not 

' have to populate that time

Dim tcoll As String

tcoll = collection.count

If  tcoll  = 1 Then

	If docForm = "Profile Doc" Then

		Call CreateTimesheet(doc)

	Else

		' do nothing

	End If

Else

	' do not do anything to create another timesheet as it already exists

End If

End Sub

Sub Email(doc As NotesDocument, uidoc As NotesUIDocument)

	' another way to send the email

Dim session As New NotesSession

Dim edoc As NotesDocument

Dim newDoc As NotesDocument

Dim rtitem As NotesRichTextItem

Set db = session.CurrentDatabase

Set newDoc = New NotesDocument( db )

Set edoc = uidoc.Document

Set rtitem = New NotesRichTextItem( newDoc, "Body" )

Call rtitem.AppendText("Please review document: ")

Call rtitem.AddNewline(1)

Call rtitem.AppendText("Request Sent by: ")

Call rtitem.AppendText(session.UserName)

Call rtitem.AddNewline(1)

Call rtitem.AppendText("For Employee: ")

Call rtitem.AppendText(uidoc.FieldGetText("EmployeeName"))

Call rtitem.AddNewline(1)

Call rtitem.AppendText("Reason for Change: ")

Call rtitem.AppendText(CReason)

Call rtitem.AddNewline(1)

If CReason = "Terminated" Then

	Call rtitem.AppendText("Date Reported: " + Cstr(uidoc.FieldGettext("Date")))

	Call rtitem.AddNewline(1)

	Call rtitem.AppendText("Last Day Worked: " + Cstr(uidoc.FieldGetText("LastDayWorked")))

	Call rtitem.AddNewline(2)

	Call rtitem.AppendText("Comment --- Since the change reason is terminated, the system has completed the timesheet and marked all days from the date of the last date worked and through the rest of the the persons work days to be 0.  Then submitted the timesheet.")

	Call rtitem.AddNewline(1)

End If

If CReason = "Quit" Then

	Call rtitem.AppendText("Date Reported: " + Cstr(uidoc.FieldGettext("Date")))

	Call rtitem.AddNewline(1)

	Call rtitem.AppendText("Last Day Worked: " + Cstr(uidoc.FieldGetText("LastDayWorked")))

	Call rtitem.AddNewline(2)

	Call rtitem.AppendText("Comment --- Since the change reason is quit, the system has completed the timesheet and marked all days from the date of the last date worked and through the rest of the the persons work days to be 0.  Then submitted the timesheet.")

	Call rtitem.AddNewline(1)

End If

Call rtitem.AddNewline(1)

Call rtitem.AppendDocLink(edoc, db.Title)

newDoc.Subject = "789 Line Entry Submitted"

Dim send(1 To 3) As String

send(1) = "Joyce Eggers"

send(2) = "Susan Putnam"

send(3) = session.UserName

Dim cc(1 To 3) As String

cc(1) = "Frank Fletcher"

cc(2) = "Steve Dries"

cc(3) = "Joyce Eggers"

Dim bcc(1 To 1) As String

bcc(1) = "Jamie Augustus"

newDoc.SendTo = send

newDoc.CopyTo = cc

newDoc.BlindCopyTo = bcc

newDoc.Send(False)

End Sub

Sub NoShow(doc As NotesDocument, uidoc As NotesUIDocument)

Dim comments As Variant

comments = doc.GetItemValue("SystemComments")



temp = Weekday(uidoc.FieldGetText("Date"))



If (comments(0) = "") Then

	'Set rtitem = doc.ReplaceItemValue("SystemComments", "")

	Set rtitem = New NotesRichTextItem(doc, "SystemComments")

Else

	Set rtitem = doc.GetFirstItem("SystemComments")

	Call rtitem.AddNewline(1)

End If

Select Case temp

Case "2" ' this Monday

	Call doc.ReplaceItemValue("Monday", "Attendance Code: No Show - 0")

	Call doc.ReplaceItemValue("MondayHours", Val(0))		

	Call doc.ReplaceItemValue("MondayCode", "No Show")

	Call rtitem.AppendText(Today() + " --- This timesheet has been edited by the system to mark Monday with 0 hours as the person was marked as a no show in a 789 line document.")

Case "3" ' this is Tueday

	Call doc.ReplaceItemValue("Tuesday", "Attendance Code: No Show - 0")

	Call doc.ReplaceItemValue("TuesdayHours", Val(0))		

	Call doc.ReplaceItemValue("TuesdayCode", "No Show")

	Call rtitem.AppendText(Today() + " --- This timesheet has been edited by the system to mark Tuesday with 0 hours as the person was marked as a no show in a 789 line document.")

Case "4" ' this is  Wednesday

	Call doc.ReplaceItemValue("Wednesday", "Attendance Code: No Show - 0")

	Call doc.ReplaceItemValue("WednesdayHours", Val(0))		

	Call doc.ReplaceItemValue("WednesdayCode", "No Show")

	Call rtitem.AppendText(Today() + " --- This timesheet has been edited by the system to mark Wednesday with 0 hours as the person was marked as a no show in a 789 line document.")

Case "5" ' this is Thursday

	Call doc.ReplaceItemValue("Thursday", "Attendance Code: No Show - 0")

	Call doc.ReplaceItemValue("ThursdayHours", Val(0))	

	Call doc.ReplaceItemValue("ThursdayCode", "No Show")

	Call rtitem.AppendText(Today() + " --- This timesheet has been edited by the system to mark Thursday with 0 hours as the person was marked as a no show in a 789 line document.")

Case "6" ' this is Friday

	Call doc.ReplaceItemValue("Friday", "Attendance Code: No Show - 0")

	Call doc.ReplaceItemValue("FridayHours", Val(0))		

	Call doc.ReplaceItemValue("FridayCode", "No Show")

	Call rtitem.AppendText(Today() + " --- This timesheet has been edited by the system to mark Friday with 0 hours as the person was marked as a no show in a 789 line document.")

Case "7" ' this is Saturday

	Call doc.ReplaceItemValue("Saturday", "Attendance Code: No Show - 0")

	Call doc.ReplaceItemValue("SaturdayHours", Val(0))

	Call doc.ReplaceItemValue("SaturdayCode", "No Show")

	Call rtitem.AppendText(Today() + " --- This timesheet has been edited by the system to mark Saturday with 0 hours as the person was marked as a no show in a 789 line document.")

Case "1" ' this is Sunday					

	Call doc.ReplaceItemValue("Sunday", "Attendance Code: No Show - 0")

	Call doc.ReplaceItemValue("SundayHours", Val(0))

	Call doc.ReplaceItemValue("SundayCode", "No Show")

	Call rtitem.AppendText(Today() + " --- This timesheet has been edited by the system to mark Sunday with 0 hours as the person was marked as a no show in a 789 line document.")

End Select

End Sub

Sub RefreshDept(doc, uidoc)

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim Dview As NotesView

Dim Dview1 As NotesView

'Dim view2 As NotesView

Dim j As Integer





' Set the values for the views and the document

Set db = session.CurrentDatabase

Set Dview = db.GetView("DAD")

Set Dview1 = db.GetView("DSET")



'Set doc = view.GetDocumentByKey(key)

'Set collection = view.GetAllDocumentsByKey(key, True)

Set collection = db.UnprocessedDocuments



For j = 1 To collection.Count

	Set doc = collection.GetNthDocument( j )

	Call doc.ComputeWithForm(False, False)

Next



Call Dview.Refresh

Call Dview1.Refresh

Call ws.ViewRefresh

End Sub