Agent to forward mail

Found this agent on lotus support site to forward email. I get an error: Object variable not set. Not a designer…need assistance. Thanks so much!

Sub Initialize

Dim s As New NotesSession 

Dim db As NotesDatabase 

Dim doc As NotesDocument 

Dim newdoc As NotesDocument 



Set db = session.currentdatabase 

Set doc=s.documentcontext 

Set newdoc = db.CreateDocument 

Call doc.CopyAllItems(newdoc, True) 

newdoc.subject="Fwd: "& newdoc.subject(0)

newdoc.copyto="" 

Call newdoc.send(False,"MSG-G&T IOU") 

End Sub

Subject: s and session

You declaring “s” as a New NotesSession, but then you are trying to get the current database from the (non-defined) “session” object…

Set db = session.currentdatabase

Should be Set db = s.currentdatabase

You should also add error handling, checking your objects after you try to create them.

If you get this kind of errors, turn on the debugger and look at the variables to see what the problem is.

In addition, I am reacting on your statement “Not a designer…”, to me it sounds kind of dangerous to let a non-designer/programmer start writing code without any training. Especially copying code from the Internet, pasting it in and trying to run it.

Subject: Session object versus s object

Appears as though session is used as the NotesSession object in the code and not “s” as declared previously.