Put a DocLink from another database

Hello, all.

I have a problem. In a databes A i create a Action Hotspot that list a view from another database B and populate a field and insert a doclink from database B document to a RichText field into database A.

But an error occur when i try append the doclink.

Can someone else help me?

Follow the code:

Sub Click(Source As Button)

Dim uiwork As New notesuiworkspace

Dim uidoc As notesuidocument

Dim session As New notessession

Dim db As notesdatabase

Dim doc As notesdocument

Dim currdoc As NotesDocument

Dim sel_doc_collection As notesdocument

Dim ask As Variant

Dim collection As NotesDocumentCollection

Dim rtf1 As NotesRichTextItem

Dim item,item1 As NotesItem

Set uidoc = uiwork.currentdocument

Set doc=uidoc.document

Set db = session.CurrentDatabase

Set currdoc = uiwork.CurrentDocument.Document

Set collection = uiwork.PickListCollection(1, False, “Server”, “databaseB.nsf”, “View”,“Project List”, “Please select a Project”)

If collection.count = 0 Then

Messagebox “User cancelled”,“No document selected”

Else

Set sel_doc_collection = collection.GetNthDocument(1)

Set rtf1 = currdoc.GetFirstItem(“DVPLink”)

'Here the field rtf1 is empty (may be because is a new document???)

Call rtf1.AppendDocLink(sel_doc_collection,“DVPLink”)

’ Here appears the error “Object variable not set”

Call rtf1.AddNewline(1)

Call uidoc.FieldSetText(“DVPCod”, sel_doc_collection.Codigo(0))

Call uidoc.FieldSetText(“ProjDes”, sel_doc_collection.Descrip(0))

Call uidoc.refresh

End If

End Sub

Tanks

João

Subject: Put a DocLink from another database

U have wronglly set the RichTextItem

Just change

Set rtf1 = currdoc.GetFirstItem(“DVPLink”)

to

Set rtf1 = New NotesRichTextItem(currdoc,"“DVPLink”)

And its should be fine then.

HTH

Tom

Subject: RE: Put a DocLink from another database

Thanks Thomas, but not work. Whitout error but the richtext field continues empty.

Subject: RE: Put a DocLink from another database

Joao,

In your code you do this:

Set currdoc = uiwork.CurrentDocument.Document

Set rtf1 = currdoc.GetFirstItem(“DVPLink”)

What is returned to rtf1? Is it just a doc link or is it a RichTextItem?

Also, are you trying to retrieve the link from database b?

In that case would you not want to use:

Set rtf1 = sel_doc_collection.GetFirstItem(“DVPLink”)

Shawn

Subject: RE: Put a DocLink from another database

Hi,

I change the code for:

Sub Click(Source As Button)

Dim uiwork As New notesuiworkspace

Dim uidoc As notesuidocument

Dim session As New notessession

Dim db As notesdatabase

Dim doc As notesdocument

Dim currdoc As NotesDocument

Dim sel_doc_collection As notesdocument

Dim collection As NotesDocumentCollection

Dim rtf1 As NotesRichTextItem

Set uidoc = uiwork.currentdocument

Set doc=uidoc.document

Set db = session.CurrentDatabase

Set currdoc=uidoc.Document

Set collection = uiwork.PickListCollection(1, False, “Server”, “databaseB.nsf”, View",“DVP List”, “Please select a DVP”)

If collection.count = 0 Then

Messagebox “User cancelled”,“No document selected”

Else

Set sel_doc_collection = collection.GetNthDocument(1)

Set rtf1 = New NotesRichTextItem(currdoc,“DVPLink”)

Call rtf1.AppendDocLink(sel_doc_collection, “Link to DVP&R”, sel_doc_collection.Codigo(0))

Call uidoc.FieldSetText(“DVPCod”, sel_doc_collection.Codigo(0))

Call uidoc.Refresh(True)

End If

End Sub

Following the debug, i verify that the instruction “Call uidoc.Refresh(True)”, clean the field DVPLink. Before this instrucion, this field contains values.

Any idea?

Thanks

Subject: RE: Put a DocLink from another database

Joao,

Try This:

Sub Click(Source As Button)

Dim uiwork As New notesuiworkspace

Dim uidoc As notesuidocument

Dim session As New notessession

Dim db As notesdatabase

Dim doc As notesdocument

Dim currdoc As NotesDocument

Dim returnedDocumentFromDatabaseB As notesdocument

Dim collection As NotesDocumentCollection

Dim rtf1 As NotesRichTextItem

Set uidoc = uiwork.currentdocument

Set doc=uidoc.document

Set db = session.CurrentDatabase

REM Set currdoc=uidoc.Document - Not used in the sub

Set collection = uiwork.PickListCollection(1, False, “Server”, “databaseB.nsf”, View",“DVP List”, “Please select a DVP”)

If collection.count = 0 Then

Messagebox “User cancelled”,“No document selected”

Exit Sub ’ if no DVP is selected we can not continue

Else

Set returnedDocumentFromDatabaseB = collection.GetNthDocument(1)

Set rtf1 = New NotesRichTextItem(doc,“DVPLink”)

Call rtf1.AppendDocLink(sel_doc_collection, “Link to DVP&R”, returnedDocumentFromDatabaseB.Codigo(0))

Call uidoc.FieldSetText(“DVPCod”, returnedDocumentFromDatabaseB.Codigo(0))

call uidoc.save ’ needed in order t refresh. Otherwise it refreshes to the saved version

Call uidoc.Refresh(True)

End If

End Sub

HTH,

Shawn

Subject: RE: Put a DocLink from another database

Thanks, Shawn

Worked

Subject: RE: Put a DocLink from another database

Hi, Shawn

In instruction "Set rtf1 = currdoc.GetFirstItem(“DVPLink”) " is returned NULL, the variable is not set. Probably because is a new document.

The field DVPLink is a RichTextItem from database A where i want insert a DocLink from the document selected from the database B

Thanks

Subject: Put a DocLink from another database

The AppendDocLink method has three properties.

Try this:

Call rtf1.AppendDocLink(sel_doc_collection,“” ,“DVPLink”)

HTH

Shawn

Subject: RE: Put a DocLink from another database

Tanks, Shawn, but not work. The error is the same.