Object Variable Not Set

I have the following email agent run to detect documents which are not complete in a database.Right now i am getting Object varible not set in the line i have documented below. Any help with error would be greatly appreciated.

Thanks,

adam

Sub Initialized

Dim workspace As NotesUIWorkspace

Dim session As NotesSession

Dim uidoc As NotesUIDocument

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim docMemo As NotesDocument

Dim bodyfield As NotesRichTextItem

Dim style As NotesRichTextStyle



Set workspace = New NotesUIWorkspace

Set session = New NotesSession

Set uidoc = workspace.CurrentDocument

Set db = session.CurrentDatabase

------> Set doc = uidoc.Document <------------

Set docMemo = New NotesDocument(db)

Set bodyfield = New NotesRichTextItem(docMemo,"Body")

Set style = session.CreateRichTextStyle



On Error Goto errorhandling



'STPeople(0) = "ecomm group"

'STPeople(1) = "<field rep?>"   



docMemo.Form = "Bookmark"

'docMemo.SendTo = STPeople

docMemo.SendTo = "Adam Herringshaw@nycm.com"

docMemo.FlowStatus = "This document has not been completed."

docMemo.Subject = "Audit Alarm"



'Agent Code

style.Bold = True

Call bodyfield.AppendText("Agent Code:  ")

style.Bold = False

Call bodyfield.AppendText(doc.agentcode(0))



Call bodyfield.AddNewline(1)

'Agent Name

style.Bold = True

Call bodyfield.AppendText("Agent Name:  ")

style.Bold = False

Call bodyfield.AppendText(doc.agentname(0))



Call bodyfield.AddNewline(1)



'Date Requested

style.Bold = True

Call bodyfield.AppendText("Date Requested:  ")

style.Bold = False

Call bodyfield.AppendText(doc.datereq1(0))



Call bodyfield.AddNewline(1)



'View DocLink

style.Bold = True

Call bodyfield.AppendText("View the document:  ")

style.Bold = False

Call bodyfield.AppendDocLink(doc, "Agent Tracking")



Call bodyfield.AddNewline(1)





Call docMemo.Send(True)

errorhandling: Print "Error: " & Cstr( Err() ) & " " & Error() & " in line: " & Cstr( Erl() )

End Sub

Subject: Object Variable Not Set

What’s the trigger for your code? Is uidoc populated?

Subject: Object Variable Not Set

Sounds like you’re running this code without having a document open in the foreground of the Notes client. Is that the case?

Subject: RE: Object Variable Not Set

I am trying to run an agent that will check a view to see if documents are not complete. If they are incomplete then send an email with the information I have programmed.

Subject: RE: Object Variable Not Set

Your code definitely won’t work, then. What your code is attempting to do is to get the currently open document (that’s what workspace.CurrentDocument is) and work with that. If there’s no currently open document, workspace.CurrentDocument returns a null value, so anything that depends upon that will be a problem. There’s nothing in the code that makes it look at a view. What you’ll want to do is get a view and loop through the documents there. Get rid of any code related to uidoc and search the help for the GetView method.