Function LSDbLookupDbl(s As NotesSession, db As NotesDatabase, servernm As String, dbname As String, vname As String, namekey As String, targetfldname As String) As Double
	' this function retrieves a document from the database (db) in a specified view
	' this function returns the resulting values of the lookup
	' Note: Adjust this lookup to return this by changing function return to variant.
	' Then return tmparray rather than the first value of the array.

	Dim lupDb As NotesDatabase      		' lookup database
	Dim lupV As NotesView          			' lookup view
	Dim lupCol As NotesDocumentCollection	' collection of lupDoc(s) that match key
	Dim lupDoc As NotesDocument  			' doc retrieved from lupV
	Dim lupItem As NotesItem  				' the field to retrieve
	Dim tmpsum As Double					' values of tmpArray added

	On Error GoTo LUpErrorHandler

	' get database
	If Not (db Is Nothing) Then
		Set lupDb = db
	Else
		Set lupDb=s.GetDatabase(servernm, dbname, False)
		If (lupDb Is Nothing) Then
			' return nothing
			LSDbLookupDbl=0
			Exit Function
		End If
	End If
	Set lupV=lupDb.GetView(vname)
	If (lupV Is Nothing) Then
		' return nothing
		LSDbLookupDbl=0
		Exit Function
	End If
	Set lupCol = lupV.GetAllDocumentsByKey(namekey, True)
	If (lupCol.Count=0) Then
		' return nothing
		LSDbLookupDbl=0
		Exit Function
	End If

	' loop through docs in lupCol and add totals
	Set lupDoc = lupCol.GetFirstDocument()
	While Not (lupDoc Is Nothing)
		' get item desired
		Set lupItem = lupDoc.GetFirstItem(targetfldname)
		If (lupItem Is Nothing) Then
			' return nothing
			LSDbLookupDbl=0
			Exit Function
		Else
			' get item value
			If (lupItem.Text="") Then
				'skip as sum is same
			Else
				tmpsum = tmpsum + CDbl(lupItem.Values(0))
			End If
		End If
		' get next doc
		Set lupDoc = lupCol.GetNextDocument(lupDoc)
	Wend
	' return result
	LSDbLookupDbl=tmpsum
	Exit Function
	
LUpErrorHandler:
	' return nothing
	LSDbLookupDbl=0
	Exit Function
End Function