Error when sending mail "Insufficient memory"

Dear all,I have this code in an agent which sends an email on a approval process…it was working perfectly for client and web users…

suddenly it started giving an error “Insufficient memory” on web…it runs on client…pls guide me what should i do

thanks

Shana

Sub Initialize

Dim session As New NotesSession

Dim doc As NotesDocument

Dim curdoc  As notesdocument

Dim doc1 As NotesDocument

Dim Rs As  Notesdocument

Dim db As NotesDatabase 

Dim docH As NotesDocument

Dim doc2 As NotesDocument

Dim viewH As NotesView

Dim view1 As NotesView

Dim avsh As Integer 

Dim view As NotesView

Dim name1 As String

Dim exsist As Boolean

Set db = session.CurrentDatabase

'Dim s As New NotesSession

Set curdoc = session.Documentcontext 



Dim x As Integer

Dim DaysCnt As Double

Dim subject As String

Dim mail As String 	

Dim category As String

Dim frmDate As Variant

'Dim fromdate As Variant 

Dim toDate,DateTo,DateFrom As Variant

Dim exceed As Boolean

Dim nowtime As Variant 

Dim frmtime As Variant

Dim totime As Variant

Dim User,User1,CUser As String



Dim username As String

'Dim LDays(1 To 365) As Variant

'Print "1"

'Set view = db.GetView("leaveTaken")

Set view = db.GetView("EmployeeRecord")'------new

Set db = session.CurrentDatabase

'Set viewH= db.GetView("Holidays") '------------------------



Dim categ As String

categ=curdoc.category(0)



Dim App,Usr As NotesName 

Set App = New NotesName(curdoc.App1(0)) 

User1=App.common

User=curdoc.name(0)



Set Usr = New NotesName(curdoc.username(0)) 

CUser=Usr.common

''//////////////////////to check if there's a manager



Dim dbDir As notesDatabase

Set dbDir =New NotesDatabase( "DominoHub/KES", "names.nsf" )

'Messagebox( dbDir.Title )	

Dim Dirview As NotesView





'Dim RS As NotesDocument

'Get employee from Employee Db

'Dim urole As String

Set Dirview = dbDir.GetView("AppraisalInfo")

'urole=curdoc.userrole(0)



'If urole<>"manager" Or urole<>"HR" Then



Dim Key,A1 As String

Key = session.CommonUserName



Set RS = Dirview.GetDocumentByKey(Key , True )	





If Not (RS Is Nothing) Then

	A1=RS.Manager(0)

	If A1="" Then

		Print "<script language='JavaScript'>"

		Print "{"

		Print "alert ('Cannot Find Manager. Please Contact HR!');"

		Print "history.go(-1);"

		Print "}"

		Print "</script>"

		Exit Sub						

	End If

End If

'End If



'-----------------------------------------validate email



Dim Rs3 As  Notesdocument

Dim Rs1 As  Notesdocument

Dim Rs2  As  Notesdocument



Dim SendTo,CopyTo,BccTo As String

Dim send,copy,bc As NotesName

Dim CopyToArray(1To 5) As String '------------

Dim i As Integer

Dim BccToArray(1To 5) As String

Dim j As Integer



Forall items In curdoc.SendTo

	Set send= New NotesName(items) 

	SendTo=send.common

	If SendTo<>"" Then

		Set RS3 = Dirview.GetDocumentByKey(SendTo , True )	

		If (RS3 Is Nothing) Then

			Print "<script language='JavaScript'>"

			Print "{"

			Print "alert ('Invalid Email in to field  '+'" & SendTo & "'+' !');"

			Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

			Print "}"

			Print "</script>"

			Exit Sub		

		End If

	End If

	'Msgbox items

End Forall



Forall items In curdoc.CopyTo

	Set copy = New NotesName(items) 

	CopyTo=copy.common

	If CopyTo<>"" Then

		Set RS1= Dirview.GetDocumentByKey(CopyTo , True )	

		If (RS1 Is Nothing) Then

			Print "<script language='JavaScript'>"

			Print "{"

			Print "alert ('Invalid Email in cc field  '+ '"& CopyTo &"' +' !');"

			Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

			Print "}"

			Print "</script>"

			Exit Sub			

		End If

	End If

End Forall



Forall items In curdoc.BlindCopyTo

	Set bc= New NotesName(items) 

	BccTo=bc.common

	If BccTo<>"" Then

		Set RS2= Dirview.GetDocumentByKey(BccTo , True )

		If (RS2 Is Nothing) Then

			Print "<script language='JavaScript'>"

			Print "{"

			Print "alert ('Invalid Email in bcc field   '+'" & BccTo & "'+' !');"

			Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

			Print "}"

			Print "</script>"

			Exit Sub				

		End If

	End If

End Forall



i=1

Forall items In curdoc.CopyTo	

	Set copy = New NotesName(items) 

	CopyTo=copy.common

	CopyToArray(i)=CopyTo

	i=i+1		

End Forall

j=1

Forall items In curdoc.BlindCopyTo

	Set bc = New NotesName(items) 

	BccTo=bc.common

	BccToArray(j)=BccTo

	j=j+1		

End Forall



'----------------------------------------validate email end



'---------------------

Set view1= db.GetView("EmployeeRecord")

username=curdoc.username(0)

Set doc2 = view1.GetDocumentByKey(username)



'------------------------------------

frmDate=curdoc.from(0)

toDate=curdoc.to(0)

	'Print"1"

%REM

Dim thisday As Variant



thisday=curdoc.today1(0)

If (thisday>frmdate) Then

	Print "<script language='JavaScript'>"

	Print "{"

	Print "alert ('From date should be a day in future!');"

	Print "history.go(-1);"

	Print "}"

	Print "</script>"

	Exit Sub				

End If

%END REM

Dim dc As NotesDocumentCollection

'Set doc1 = view.GetFirstDocument

Set dc=view.GetAllDocumentsByKey(curdoc.name(0),False)

Set doc1=dc.GetFirstDocument

%REM

While Not(doc1 Is Nothing)

'	Forall name2 In doc1.name

			'If( name2=User)Then

	Forall tdate In doc1.to

		Forall fromdate In doc1.from

			

			If(Cdat(fromdate)<=Cdat(frmDate) And Cdat(frmDate)=<Cdat(tdate))Then

				exsist=True

			Elseif(Cdat(fromdate)<=Cdat(toDate) And Cdat(toDate)=<Cdat(tdate))Then

				exsist=True

			End If

		End Forall 

	End Forall

		'End If

	'End Forall

	Set doc1= dc.GetNextDocument(doc1)

Wend



If (exsist=True) Then

	Print "<script language='JavaScript'>"

	Print "{"

	Print "alert ('You have already applied for leave in the selected date !');"

	Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

	Print "}"

	Print "</script>"

	Exit Sub		

		'----------------

	

End If

%END REM

If (categ<>"short leave") Then

	DateFrom= curdoc.from(0) 

	DateTo= curdoc.to(0) 

	If curdoc.country(0)="Sri Lanka" Then

		Set viewH = db.GetView( "Holidays" )

	Elseif curdoc.country(0)="India" Then

		Set viewH = db.GetView( "InHolidays" )

	Elseif curdoc.country(0)="Malysia" Then

		Set viewH = db.GetView( "MalHolidays" )

	End If

	

	

	Dim LDays(1 To 365) As Variant

	Dim wkday As Boolean

	Dim half As String

	wkday=False

	

	Dim AADays As New notesdatetime(Cdat(DateFrom))

	Set doc = viewH.GetDocumentByKey( Cdat(AADays.DateOnly) )

	If doc Is Nothing Then

		LDays(1)=DateFrom

		x=1

		DaysCnt=0

	Else	

		x=0

	End If	

	

	While Cdat(AADays.DateOnly)<Cdat(DateTo)

		x=x+1

		'Call AADays.AdjustDay(1)

		If Weekday(AADays.Dateonly)<>1 Then

			If Weekday(AADays.Dateonly)<>7 Then

				Set doc = viewH.GetDocumentByKey( Cdat(AADays.DateOnly) )

				wkday=True

				If doc Is Nothing  Then

					

					LDays(x)=AADays.Dateonly

					DaysCnt=DaysCnt+1

				Else 

					half=doc.half(0)

					If half="half day" Then

						DaysCnt=DaysCnt+0.5

					End If

				End If	

			End If	

		End If

		Call AADays.AdjustDay(1)

	Wend

	

	Dim ishalf As Boolean

	While Cdat(AADays.DateOnly)=Cdat(toDate)

		x=x+1

		'Call AADays.AdjustDay(1)

		If Weekday(AADays.Dateonly)<>1 Then

			If Weekday(AADays.Dateonly)<>7 Then

				Set docH = viewH.GetDocumentByKey( Cdat(AADays.DateOnly) )

				wkday=True

				If docH Is Nothing  Then

					LDays(x)=AADays.Dateonly

					DaysCnt=DaysCnt+1

				Else 

					half=docH.half(0)

					If half="half day" Then

						DaysCnt=DaysCnt+0.5

						ishalf=True

					End If	

				End If 

			End If

		End If

		Call AADays.AdjustDay(1)

	Wend

%REM

	If Cdat(AADays.DateOnly)=Cdat(DateTo) Then

		If Weekday(AADays.Dateonly)<>1 Then

			If Weekday(AADays.Dateonly)<>7 Then

				wkday=True

			End If	

		End If	

	End If

	

	If (wkday=True) Then

		DaysCnt=DaysCnt+1

	End If

%END REM

'Set doc=uidoc.document

’ curdoc.no=DaysCnt

	Dim num1,num2,num3 As Double 

	Dim frmHalf,toHalf,half1 As String 

	

	frmHalf=curdoc.frmHalf(0)

	toHalf=curdoc.toHalf(0)

	half1=curdoc.Half(0)

	

	If frmDate=toDate Then

		frmHalf="full day"

		toHalf="full day"

	End If

	If frmDate<>toDate Then

		half1="full day"

	End If

	

	If frmHalf="2nd half"  Then

		num1=-0.5			

	End If

	

	If ishalf=True Then

		If toHalf="2nd half" Then

			num2=-0.5

		End If

	Else

		If toHalf="1st half" Then

			num2=-0.5

		End If

	End If 

	

	If ishalf=True Then

		If half1="2nd half" Then

			num3=-0.5

		End If

	Else

		If half1<>"full day" Then

			num3=-0.5

		End If

	End If 

	

'Call uidoc.Refresh

	curdoc.no = DaysCnt+num1+num2+num3

	

	

	'--------------------------------to update leave taken fields

	Dim totCas As Double 

	Dim totAn As Double

	Dim totOther As Double

	Dim totSick As Double 

	Dim AVSP,AVANN,AVCAS As Double 

	Dim noOfDays As Double

	exceed=False

	noOfDays=Cdbl(curdoc.no(0))

	'-------------------------

	If (wkday=False) Then

		Print "<script language='JavaScript'>"

		Print "{"

		Print "alert ('Request for leave in week ends is not applicable!');"

		Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

		Print "}"

		Print "</script>"

		Exit Sub			

	Elseif (noOfDays=0) Then

		Print "<script language='JavaScript'>"

		Print "{"

		Print "alert ('Number of days should be greater than zero !');"

		Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

		Print "}"

		Print "</script>"

		Exit Sub			

	End If

	

	

	If (categ="casual") Then

		avCas=Cdbl(curdoc.avCasual(0))

		If (noOfDays>avCas) Then

			exceed=True

		Else

			curdoc.casual=noOfDays

			totCas=doc2.totCasual(0)

			totCas=totCas+noOfDays

			'doc2.totCasual=totCas

			Call doc2.ReplaceItemValue("totCasual",totCas)

			'Print totCas

		End If

	Elseif (categ="annual") Then

		avAnn=Cdbl(curdoc.avAnnual(0))

		If (noOfDays>avAnn) Then

			exceed=True

		Else

			curdoc.annual=noOfDays

			totAn=doc2.totAnnual(0)

			totAn=noOfDays+totAn

			Call doc2.ReplaceItemValue("totAnnual",totAn)

		End If

	Elseif (categ="special leave") Then

		avSp=Cdbl(curdoc.avSpecialLeave(0))

		If (noOfDays>avSp) Then

			exceed=True

		Else

			curdoc.special=noOfDays

			totOther=doc2.totSpecial(0)

			totOther=totOther+noOfDays

			Call doc2.ReplaceItemValue("totSpecial",totOther)

		End If

		'-----------------------------------for sick leave

		Dim avSick As Double 

	Elseif (categ="sick") Then

		avSick=Cdbl(curdoc.avSick(0))

		If (noOfDays>avSick) Then

			exceed=True

		Else

			curdoc.sick=noOfDays

			totSick=doc2.totSick(0)

			totSick=totSick+noOfDays

			Call doc2.ReplaceItemValue("totSick",totSick)

		End If

		'-------------------------------

	Elseif (categ="no pay") Then

		Dim totNopay As Double

		curdoc.noPay=noOfDays

		totNopay=doc2.noLeave(0)

		totNopay=totNopay+noOfDays

		Call doc2.ReplaceItemValue("noLeave",totNopay)

		

	End If	

	'-------------------------------------

'---------- check available leave

	If (exceed=True) Then

		Print "<script language='JavaScript'>"

		Print "{"

		Print "alert ('You have exceeded the available balance !');"

		Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

		Print "}"

		Print "</script>"

		Exit Sub			

		

		

	End If

	

	

	

	

Elseif categ="short leave" Then

	Dim StartTime,EndTime As Variant 

	

	StartTime= curdoc.fromTime(0) 

	EndTime= curdoc.toTime(0) 	

	

	

	Dim shmonth,thismonth As Variant

	shmonth=Month(frmDate)

	thismonth=Month(curdoc.Date_Created(0))

	If shmonth<>thismonth Then

		Print "<script language='JavaScript'>"

		Print "{"

		Print "alert ('You can not apply short leave for another month');"

		Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

		Print "}"

		Print "</script>"

		Exit Sub

	End If

	

	'Dim StartTime As NotesDateTime

	'Dim EndTime As NotesDateTime			

	

	Set StartTime = New NotesdateTime(Cdat(StartTime))

	Set EndTime = New NotesdateTime(Cdat(EndTime))			

	

	curdoc.time=Cstr(EndTime.TimeDifference( Starttime)/60)

	

	Dim total As Long

	Dim hours As Long

	Dim minutes As Long

	Dim seconds As Long

	Dim TotTime As String

	Dim mins As Long 

	

	total = EndTime.TimeDifference( Starttime)

	

	mins=total/60

	hours = total / 3600

	total = total - (hours * 3600)

	minutes = total / 60

	

	TotTime=Cstr(hours) + ":" +Cstr(minutes)

	

	avSh=Cint(curdoc.avShortLeave(0))

	If (mins=0) Then

		Print "<script language='JavaScript'>"

		Print "{"

		Print "alert ('From time and to time can not be the same!');"

		Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

		Print "}"

		Print "</script>"

		Exit Sub			

	Elseif (mins>avSh) Then

		exceed="true"			

		Print "<script language='JavaScript'>"

		Print "{"

		Print "alert ('You have exceeded the available balance !');"

		Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

		Print "}"

		Print "</script>"

		Exit Sub			

		

	Else		

		Dim totShleave As Integer

		curdoc.time=mins

		curdoc.shortLeave=mins

		totShleave=doc2.totShleave(0)

		totShleave=totShleave+mins

		Call doc2.ReplaceItemValue("totShleave",totShleave)

		'doc.time=time1

	End If

'		

End If		

'-------------------new msg



Print "<script language='JavaScript'>"

Print "{"

Print "alert ('Leave Application  is sent to the manager ');"

Print "history.go(-1);"

	'Print "javascript:history.go(-2);"

Print "}"

Print "</script>"

'Exit Sub			



'-------------------new msg end

’ Dim nowtime As Variant

'nowtime=curdoc.Date_Created_1(0)

nowtime = Format$(GetServerDateTime.LSLocalTime, "mm/dd/yyyy  hh:nn:ss") 	

subject = "Leave Request from "+User+" Requires Your Approval"

mail = "This is to inform you that " + User + " has Applied Leave from " + Cstr(DateFrom) + " to " + Cstr(DateTo)

'Call MailSend(doc.App1, "", subject, mail, doc)

curdoc.DocHistory= Cstr("Requested by " & CUser & " on " & nowtime)

Call MailSend(User1, CopyToArray,BccToArray, subject, mail, curdoc)

curdoc.Flag ="1"

curdoc.status="Submitted"

'Msgbox "The document is sent to"+" "+curdoc.App1(0)+"! " , 64,"Confirmation"



curdoc.SaveOptions ="1"

curdoc.Form = "NewRequestLeave"

Call curdoc.Save (True,False)

Call doc2.Save (True,False)

'curdoc.refresh

’ Call workspace.SetTargetFrame(“content”)

’ Call workspace.ComposeDocument( “”, “”, “NewRequestLeave”, , ,False)

End Sub

Subject: Error when sending mail “Insufficient memory”

Try searching here… i just did a quick search and came back with 186 entries,