Self_Taught
New Member
- Joined
- Nov 20, 2013
- Messages
- 6
I'm using VBA to query a Lotus db and it works but so far I can only get it to pull all records in the specified view. Anyone have an idea how I could get this to pull only records where a specific field met certain criteria?
For example... In the code below I would only want to pull records where Value02 was not null
Private Sub CommandButton1_Click()
Dim Ans, session, db, View, doc, i, strShtName, Value01, Value02
Ans = MsgBox("Proceed?", vbYesNo, "Confirm")
Select Case Ans
Case vbNo
Exit Sub
End Select
Set session = CreateObject("Notes.NotesSession")
'##### define Notes server and file path
Set db = session.GetDatabase("server", "dir\file.nsf")
'##### get Notes view
Set View = db.getView("view01")
i = 2
Set strShtName = ActiveSheet
Set doc = View.GetFirstDocument
Do Until doc Is Nothing
Value01 = doc.GetItemValue("DB_Value01")
Value02 = doc.GetItemValue("DB_Value02")
strShtName.Cells(i, 2) = Value01(0)
strShtName.Cells(i, 3) = Value02(0)
Set doc = View.GetNextDocument(doc)
i = i + 1
Loop
strShtName.Range(Cells(2, 1), Cells(i, 3)) _
.Sort Key1:=strShtName.Cells(1, 3), order1:=xlAscending, _
Key2:=strShtName.Cells(1, 2), order2:=xlAscending
MsgBox "Finish!"
End Sub
For example... In the code below I would only want to pull records where Value02 was not null
Private Sub CommandButton1_Click()
Dim Ans, session, db, View, doc, i, strShtName, Value01, Value02
Ans = MsgBox("Proceed?", vbYesNo, "Confirm")
Select Case Ans
Case vbNo
Exit Sub
End Select
Set session = CreateObject("Notes.NotesSession")
'##### define Notes server and file path
Set db = session.GetDatabase("server", "dir\file.nsf")
'##### get Notes view
Set View = db.getView("view01")
i = 2
Set strShtName = ActiveSheet
Set doc = View.GetFirstDocument
Do Until doc Is Nothing
Value01 = doc.GetItemValue("DB_Value01")
Value02 = doc.GetItemValue("DB_Value02")
strShtName.Cells(i, 2) = Value01(0)
strShtName.Cells(i, 3) = Value02(0)
Set doc = View.GetNextDocument(doc)
i = i + 1
Loop
strShtName.Range(Cells(2, 1), Cells(i, 3)) _
.Sort Key1:=strShtName.Cells(1, 3), order1:=xlAscending, _
Key2:=strShtName.Cells(1, 2), order2:=xlAscending
MsgBox "Finish!"
End Sub