Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why this error always prompt out "Object variable not set"

Status
Not open for further replies.

echain

Programmer
Sep 8, 2000
52
CA
I wrote a simple script on an agent to copy documents which is before 2000,10,12 from current database to the new database

See the script:
Dim archiveDb As New NotesDatabase("server name","database.nsf ")
Dim doc As NotesDocument
If (doc.Created < Datenumber( 2000,10,12)) Then
Call doc.CopyToDatabase(archiveDb)
End If
When I run it. The error message prompt out&quot;Object variable not set&quot;. What should I do?
Thank you for your help! [sig][/sig]
 
You need to set the value of doc and you won't get this error message.

Example--if you were to run this on the current document
you could have the following code:

Dim session As New NotesSession
Dim archiveDb As New NotesDatabase(&quot;server name&quot;,&quot;database.nsf &quot;)
Dim doc As NotesDocument
Set doc=Session.DocumentContext
If (doc.Created < Datenumber( 2000,10,12)) Then
Call doc.CopyToDatabase(archiveDb)
End If


or, if you are running this on documents in a view, use the getFirstDocument method of NotesView to loop through the documents and copy to archive database
Example: GetFirstDocument method

This script gets the first document in the Open\By Project & Priority view of a database.
Dim db As New NotesDatabase( &quot;Gaborone&quot;, &quot;todo.nsf&quot; )
Dim view As NotesView
Dim doc As NotesDocument
Set view = db.GetView( &quot;Open\By Project & Priority&quot; )
Set doc = view.GetFirstDocument
If doc.HasItem(&quot;Subject&quot;) Then
While Not(doc Is Nothing)
Forall subject In doc.GetItemValue(&quot;Subject&quot;)
Messagebox subject
End Forall
Set doc = view.GetNextDocument(doc)
Wend
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top