"Object Variable Not Set"

Hi! I has try use the session documentContext in lotus script but it return object variable not set, below is the code that i use to try for (After mail arriveds event), please comment. Thanks!

Sub Initialize

Dim session As NotesSession

Dim docIn As NotesDocument

Dim db As NotesDatabase

On Error Goto ErrProcess

Set session = New NotesSession

Set db=session.CurrentDatabase

Set docIn=session.DocumentContext

clientAddress = docIn.From(0)

clientSubject = docIn.Subject(0)

Msgbox clientsubject

Exit Sub

ErrProcess:

Print "Error " & Err() & ": " & Error()

End Sub

Subject: “Object Variable Not Set”

Use the “Before New Mail Arrives” event

Subject: RE: “Object Variable Not Set”

  1. Please don’t encourage people to use the “before” mail trigger; pre-delivery agents are extremely expensive, may be prohibited by admin settings, and are certainly not some catchall for a post-delivery agent that doesn’t work.

  2. The problem is that you’re using documentcontext. Pardon the unintended pun, but it is not in context in a mail-triggered agent. Look up notesdatabase.unprocesseddocuments; that’s what you want to use instead.