Error : Object variable not set

Hi,

I am attaching an attachment in RichText field.

I am getting an error message " Object Variable not set."

However, when I bring the doc in edit mode and simply save it without any change and then try to attach the attachment then its working fine.

Next time, when I open the doc and try to attach the attachment it works fine.

Here is the code which I am using:

=============================================

Sub Click(Source As Button)

Dim s As New NotesSession		

Dim db As NotesDatabase 		

Dim ws As New NotesUIWorkspace 		

Dim uidoc As NotesUIDocument 		

Dim doc As NotesDocument 		

Dim varitem As Variant

Dim rtitem As NotesRichTextItem



Set db = s.currentdatabase

Set uidoc = ws.currentdocument

Set doc = uidoc.document



filenames =  ws.OpenFileDialog(False, "Select an image to be attached", ,"c:\bds\image")



If Not(Isempty(filenames)) Then		

	Set rtitem = doc.Getfirstitem( "Ima" ) 

	'attach the worksheet

	Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "",  filenames(0)) 

	size& = object.FileSize

	If (size& > 100000) Then 

		conform= Msgbox ("Image size is greater than 100KB. Please attach an image having size <=100 KB" , 4144,|Image Size| )

		Forall i In rtitem.EmbeddedObjects		

			If i.type = EMBED_ATTACHMENT Then				

				Call i.Remove

			End If

		End Forall			

		Exit Sub

	End If

	attachmentname$ = Object.Source

	Call rtitem.Update 

	Call doc.ReplaceItemValue("a_1", "True")

End If



'update the screen with the attachment

Call doc.Save(False,False)



Dim DocUNID As String

DocUNID = doc.UniversalID



doc.SaveOptions = "0"

Call uidoc.Close



Set doc = db.GetDocumentByUNID(DocUNID)

Set uidoc = ws.EditDocument(True, doc)

uidoc.GotoField("Ima")

End Sub

=============================================

Its giving me error on the following line:

Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, “”, filenames(0))

Thanks so much in advance

L TYAGI

Subject: Two thoughts, one obvious, one not…

Obvious: The field “Ima” doesn’t exist until you save the document the first time, so rtitem is in fact not set. One must use createRichtextItem to make a blank field to hold an attachment, as indicated in Help, if this is a new document. Best to check, anyway.

Not obvious: My experience is that LS will not assign a richtext item directly to a NotesRichtextItem object. Help Examples don’t do this, and neither should you. Instead one must fetch a NotesItem, then check it’s Type property to see if it is RICH_TEXT, then assign that NotesItem to a NotesRichtextItem. I’ve never understood this Rube Goldberg process, but every single time I have not used it, I’ve been burned.

  • It strikes me that always better to exhaust Help, and Forum searching, before pasting a bunch of code and asking why it doesn’t work. Both of these solutions are either directly in Help, or may be inferred from Examples in Help, at least in the Domino Database version of it.

  • That make me wonder if you did try DDE Help and gave up. I could understand that … I’ve been using Domino for twelve years and I avoid DDE Help like anthrax. Here’s hoping this, too, is fixed in 8.5.1.

  • Hope thishelps. Gosh but I ramble…