Cannot create new NotesDocument object

Hi all

I’m trying to create a new document in the current database, but i’m getting the following issue:

Sub getFlow(doc as NotesDocument,dFlow as NotesDocument)

 Dim view As NotesView

 Dim strKey as String



 Set view = doc.ParentDatabase.GetView("VFLOW")

 If view is Nothing then

     Exit Sub

 End If

 strKey = doc.FLD_KEY(0)

 Set dFlow = view.GetDocumentByKey(strKey,true)

 If dFlow Is Nothing Then

      Set dFlow = New NotesDocument(doc.ParentDatabase)

      dFlow.FLD_KEY = strKey 'Object Variable not set error

      .... 'Set all other fields

      Call dFlow.Save(True,False)

 End If

End sub

 Anyone can help with this issue

Thanks in advance

Subject: Cannot create new NotesDocument object

Instead of this line: dFlow.FLD_KEY = strKey 'Object Variable not set error

use this:

Dim item as NotesItem

Set item = dFlow.ReplaceItemValue( “FLD_KEY”, strKey )

Subject: RE: Cannot create new NotesDocument object

I’d do the whole thing more like this (untested):

Sub getFlow (doc as NotesDocument)

If doc is Nothing then

Error 1001, “Required parameter was missing.”

End If

Dim db as NotesDatabase

Set db = doc.ParentDatabase

Dim view As NotesView

Set view = db.GetView(“VFLOW”)

If view is Nothing then

Error 1001, “Required View was missing.”

End If

Dim strKey as String

strKey = doc.FLD_KEY(0)

Dim dFlow as NotesDocument

Set dFlow = view.GetDocumentByKey(strKey,true)

If dFlow Is Nothing Then

Set dFlow = New NotesDocument(db)

Dim item as NotesItem

Set item = dFlow.ReplaceItemValue( “FLD_KEY”, strKey )

Set item = dFlow.ReplaceItemValue( “More Items”, “Other Values” ) 'Set all other fields

Call dFlow.ComputeWithform(True,False)

Call dFlow.Save(True,False)

End If

End sub

Subject: RE: Cannot create new NotesDocument object

Brian,

The dFlow argument is required because i’ve to manipulate the document outside this function. I already tried to return the document but get same error.

Subject: RE: Cannot create new NotesDocument object

I see, then I usually make it a function that returns the document…

Function getFlow (doc as NotesDocument) as NotesDocument

If doc is Nothing then

Error 1001, “Required parameter was missing.”

End If

Dim db as NotesDatabase

Set db = doc.ParentDatabase

Dim view As NotesView

Set view = db.GetView(“VFLOW”)

If view is Nothing then

Error 1001, “Required View was missing.”

End If

Dim strKey as String

strKey = doc.FLD_KEY(0)

Set getFlow = view.GetDocumentByKey(strKey,true)

If getFlow Is Nothing Then

Set getFlow = New NotesDocument(db)

Dim item as NotesItem

Set item = getFlow.ReplaceItemValue( “Form”, “FLOW_Form” )

Set item = getFlow.ReplaceItemValue( “FLD_KEY”, strKey )

Set item = getFlow.ReplaceItemValue( “More Items”, “Other Values” ) 'Set all other fields

Call getFlow.ComputeWithform(True,False)

Call getFlow.Save(True,False)

End If

End Function

Subject: RE: Cannot create new NotesDocument object

I think its using ReplaceItemValue rather than the extended syntax that is the actual fix for your issue. (Restructuring your sub/function is just me being obsessive. )

Subject: RE: Cannot create new NotesDocument object

No, it absolutely is not. The ONLY case I’ve seen where there has been an actual difference is the assignment of an array of NotesDateTime objects to a field. (There is, of course, the option to assign item flags as well, but since that isn’t in play here it’s a moot point.) And this from a guy who much prefers the explicit method call.

Subject: RE: Cannot create new NotesDocument object

Stan’s right about that, of course. Sorry. :-/ That won’t make a difference.

Keep in mind that Stan’s the brain in this thread, but I think this should work.

Sub YourMainRoutine

Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase



' This is the doc with 'strKey'

Dim doc As NotesDocument

Set doc = New NotesDocument ( db )

Dim item As NotesItem

Set item = doc .ReplaceItemValue( "strKey", "TestKeyValue" )



' Get the flowDoc from the function.

Dim flowdoc As NotesDocument

Set flowdoc = getFlow ( doc )

End Sub

Function getFlow (doc As NotesDocument) As NotesDocument

If doc Is Nothing Then Error 1001, "Required parameter was missing."



Dim db As NotesDatabase

Set db = doc.ParentDatabase



Dim view As NotesView

Set view = db.GetView("VFLOW")

If view Is Nothing Then Error 1002, "Required View was missing."



Dim strKey As String

strKey = doc.FLD_KEY(0)

If strKey ="" Then Error 1003, "Required value was missing."



Dim tempDoc As NotesDocument

Set tempDoc = view.GetDocumentByKey(strKey,True)

If tempDoc Is Nothing Then

	Set tempDoc = New NotesDocument(db)

	Dim item As NotesItem

	Set item = tempDoc.ReplaceItemValue( "Form", "FLOW_Form" )

	Set item = tempDoc.ReplaceItemValue( "FLD_KEY", strKey )

’ …

	Set item = tempDoc.ReplaceItemValue( "More Items", "Other Values" ) 'Set all other fields

’ …

	Call tempDoc.ComputeWithform(True,False)

	Call tempDoc.Save(True,False)

End If



Set getFlow = tempDoc

End Function

Subject: RE: Cannot create new NotesDocument object

Hi Brian!

Actually i did something as you posted. I initialized the dFlow doc before calling the routine instead of in the routine. It’s a workaround. Searching the forum i’ve seen similar issues but the problem was Domino deleting the objects after the end of a function. But it doesn’t look to be the same, as i’m passing the objects to the function.

Thanks you all.

Subject: RE: Cannot create new NotesDocument object

You guys are talking at cross-purposes. Cesar is using the extended class syntax of the NotesDocument to set field values; Brian is using the explicit method. They are exactly equivalent.

The problem is that dFlow is not set inside the subroutine in the original posting, and it will not be set outside the function in the code in Brian’s second posting. Cesar – you need to either pass dFlow into the subroutine as an argument or make it avaliable as a global variable, otherwise it will not be available both inside and outside the sub.

Subject: RE: Cannot create new NotesDocument object

“The problem is that dFlow is not set inside the subroutine in the original posting.” - Isn’t he doing that here?

Set dFlow = view.GetDocumentByKey(strKey,true)

If dFlow Is Nothing Then

Set dFlow = New NotesDocument(doc.ParentDatabase)

“…and it will not be set outside the function in the code in Brian’s second posting.” - In the sub that calls my function you do something like this.

Dim flowDoc as NotesDocument

Set flowDoc = getFlow (doc) ’ Call the function

I didn’t test it, but it seems like it should work to me.

Subject: RE: Cannot create new NotesDocument object

In the original (assuming that dFlow is declared in Sub Initialize rather than as a global), dFlow is an undeclared Variant, but that’s not the point. The “object variable not set” is dFlow. We can tell that because it’s the only object variable used on the line that is throwing the error. It doesn’t matter what the code prior to that point is ATTEMPTING to do, the fact is that it hasn’t happened.

Which brings us to using the debugger. Stepping through the code would show what’s happening.