Need help with remove doc

HiI want to remove all doc in aview there field orderOK is 0. I’m not use LS so often and is stuck here. Could anyone help me.

Sub Initialize

Dim session As New Notessession

Dim thisDb As NotesDatabase

Dim dc As NotesDocumentCollection

Dim v As NotesView

Dim doc As NotesDocument

Dim docStatus As NotesDocument

Dim profileDoc As Notesdocument

Dim Server As Variant

Dim DB As Variant

Dim collection As NotesDocumentCollection



Print "Delete document, Started at: " + Now



Set DB = session.CurrentDatabase

'Set Server = session.ServerName

'name$ = session.ServerName



Dim DBdoc As New NotesDatabase(Server(0), DB(0))



Set view = DB.GetView( "($All)" )	

Set doc = view.GetFirstDocument

Set docStatus = session.DocumentContext



If(doc.orderOK(0)="0")	 Then

	

' Remove document

	While Not doc Is Nothing		

		Set docNext = view.GetNextDocument(DBdoc)

		Call doc.remove(True)

		Set doc = docNext	

	Wend	

	

End If



Print "Delete document, Finished at: " + Now

End Sub

Kind regards

Fredrik

Subject: Need help with remove doc

Hi,

make a NotesviewEntryCollection with the method GetallEntrysBykey. And dann Remove them all…

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim vc As NotesViewEntryCollection

Set db = session.CurrentDatabase

Set view = db.GetView(“By Category”) 'your view

Set vc = view.GetAllEntriesByKey(“December”) 'your Fieldvalue

Call vc.RemoveAll(True) 'force to delete

Subject: Need help with remove doc

Looping through all the documents and then checking for the condition would make a impact on the server performance if the number of docs to delete are more.

Do like this -

  1. Create a view with the selection formula set like -

Select form=“formname” & orderOK = “0”

  1. Write the following code -

Sub Initialize

Dim session as new notessession

Dim db as notesdatabase

Dim vw as notesview

Dim vc as notesviewentrycollection

set db= session.currentdatabase

set vw = db.getview(“viewname”)

set vc=vw.Allentries

vc.remove

msgbox “All docs removed”

End sub

Hope this helps.

–Phani