|
||||
Note: The return value for @DBColumn can be used in dialogbox.
Function DbColumn(strServer
As String, strDB As String, strView
As String, column As Variant)
Dim session As notesSession
Dim db As notesDatabase
Dim dbTmp As notesDatabase
Dim viewTmp As NotesView
Dim docCTmp As
notesDocumentCollection
Dim docTmp As notesDocument
Dim col As notesViewColumn
Dim itm As notesItem
Dim iTmp As Integer
Dim aList() As String
Dim i As Integer
Dim j As Integer
Dim strField As String
Dim strFormula As String
Dim strLS As String
Set session = New NotesSession
Set db = session.currentDatabase
If strServer = "" Then
strServer = db.Server
End If
If strDB = "" Then
Set dbTmp = db
Else
Set dbTmp = session.GetDatabase
(strServer, strDB)
End If
If dbTmp Is Nothing Then
Msgbox "Attempt to lookup to a
non-existent database on " & strServer,
MB_ICONSTOP + MB_OK, "Error"
DbColumn = ""
Exit Function
End If
Set viewTmp = dbTmp.GetView(strView)
If viewTmp Is Nothing Then
Msgbox "DBCOLUMN : Attempt to lookup
to a non-existent view " & strView & ",
Server=" & dbTmp.Server & " NSF=" &
db.FilePath, MB_ICONSTOP + MB_OK, "Error"
DbColumn = ""
Exit Function
End If
Set docTmp = viewTmp.GetFirstDocument
iTmp = 0
While Not (docTmp Is Nothing)
Select Case Datatype(column)
Case V_STRING:
strField = column
ITM_NAME:
Set itm = docTmp.GetFirstItem(strField)
If itm Is Nothing Then
valTmp = Null
Else
valTmp = itm.values
End If
Case V_INTEGER, V_LONG:
Set col = viewTmp.Columns(column-1)
strFormula = col.Formula
If strFormula = "" Then
strField = col.ItemName
Goto ITM_NAME
Else
Set docG = docTmp
strLS = "valTmp = Evaluate(""" &
strFormula & """, docG)"
Execute strLS
End If
Case Else:
Msgbox "Invalid parameter for DbColumn",
MB_ICONSTOP + MB_OK, "Error"
Exit Function
End Select
If Not Isnull(valTmp) Then
For j = 0 To Ubound(valTmp)
Redim Preserve aList(iTmp)
aList(iTmp) = valTmp(j)
iTmp = iTmp + 1
Next
End If
Set docTmp = viewTmp.
GetNextDocument(docTmp)
Wend
If iTmp = 0 Then
DbColumn = ""
Else
DbColumn = aList
End If
End Function
Function DbLookup(strServer As String,
strDB As String, strView As String,
strKey As String, column As Variant)
Dim session As notesSession
Dim db As notesDatabase
Dim dbTmp As notesDatabase
Dim viewTmp As NotesView
Dim docCTmp As
notesDocumentCollection
Dim docTmp As notesDocument
Dim col As notesViewColumn
Dim itm As notesItem
Dim iTmp As Integer
Dim aList() As String
Dim i As Integer
Dim j As Integer
Dim strField As String
Dim strFormula As String
Dim strLS As String
Set session = New NotesSession
Set db = session.currentDatabase
If strServer = "" Then
strServer = db.Server
End If
If strDB = "" Then
Set dbTmp = db
Else
Set dbTmp = session.GetDatabase
(strServer, strDB)
End If
If dbTmp Is Nothing Then
Msgbox "Attempt to lookup to a
non-existent database on " & strServer,
MB_ICONSTOP + MB_OK, "Error"
DbLookup = ""
Exit Function
End If
Set viewTmp = dbTmp.GetView(strView)
If viewTmp Is Nothing Then
Msgbox "DBLOOKUP : Attempt to lookup
to a non-existent view " & strView & ",
Server=" & dbTmp.Server & " NSF=" &
db.FilePath, MB_ICONSTOP + MB_OK, "Error"
DbLookup = ""
Exit Function
End If
Set docCTmp = viewTmp.
GetAllDocumentsbyKey(strKey , True)
iTmp = 0
For i = 1 To docCTmp.count
Set docTmp = docCTmp.GetNthDocument(i)
Select Case Datatype(column)
Case V_STRING:
strField = column
ITM_NAME:
Set itm = docTmp.GetFirstItem(strField)
If itm Is Nothing Then
valTmp = Null
Else
valTmp = itm.values
End If
Case V_INTEGER, V_LONG:
Set col = viewTmp.Columns(column-1)
strFormula = col.Formula
If strFormula = "" Then
strField = col.ItemName
Goto ITM_NAME
Else
strField = col.ItemName
Set docG = docTmp
strLS = "valTmp = Evaluate(""" &
strFormula & """, docG)"
Execute strLS
End If
Case Else:
Msgbox "Invalid parameter for DbLookup",
MB_ICONSTOP + MB_OK, "Error"
Exit Function
End Select
If Not Isnull(valTmp) Then
For j = 0 To Ubound(valTmp)
Redim Preserve aList(iTmp)
aList(iTmp) = valTmp(j)
iTmp = iTmp + 1
Next
End If
Next
If iTmp = 0 Then
DbLookup = ""
Else
DbLookup = aList
End If
End Function
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip library by member Nithya K. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our tip contest and you could win a prize.
This was first published in June 2007