Scanner + rt.EmbedObject not working

Hi everyone!

I’ve made an action button, which makes scans a document (through TWAIN), and (…must do…) places it’s image to a “Scan” field. But: when I try to rtff.EmbedObject I cannot see the file attachment. Furthermore, when I save a doc, I can see a $FILE and $OLEOBJINFO properties in a doc, but I still cannot see the attachment!

What’s wrong?

The scanning code is:

Sub Click(Source As Button)

Const SCANFILEPATH$={C:\temp\doc.jpg}

Const IMPORTFILETYPE$={JPEG}

Const RTFNAME$={Scan}

Const SCANOBJNAME$={Kodak Image Scan Control}

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim scanner As Variant

Dim db As notesdatabase

Dim s As New notessession

Dim doc As notesdocument

Dim fileTemp As String

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.document

Set db = s.currentdatabase

Call uidoc.GoToField(“Scan”)

On Error Resume Next

Set scanner = uidoc.GetObject(“Kodak Image Scan Control”)

scanner.MultiPage = 1

If scanner.ScannerAvailable=False Then

Messagebox "Сканнер не доступен!"

Else

' scanner.ShowSelectScanner		

scanner.image=SCANFILEPATH$

scanner.ScanTo=2

scanner.PageOption=6

Call scanner.SetPageTypeCompressionOpts(3, 5, 8, 24124)

scanner.ShowSetupBeforeScan=True

			

scanner.OpenScanner 

scanner.StartScan

	

Call scanner.CloseScanner



Dim rtff As Variant 'NotesRichTextItem

Set rtff = uidoc.Document.GetFirstItem("Scan")

If ( rtff.Type = RICHTEXT ) Then

	Call rtff.EmbedObject(EMBED_ATTACHMENT, "", SCANFILEPATH$)

	Call uidoc.Document.Save(True, False)

	Call uidoc.Refresh

	End If

End If

End Sub

Thanks in advance,

Dmitry.

P.S. By the way, when I use CreateObject instead of EmbedObject, it works ok, in sense that it places a 2Megabyte image to a scan field (instead of 80K attached file)…

Subject: Scanner + rt.EmbedObject not working

The key is these two lines:

	Call rtff.EmbedObject(EMBED_ATTACHMENT, "", SCANFILEPATH$)

	Call uidoc.Document.Save(True, False)

In the first, you embed the attachment into the back end document, while in the second, you overwrite the changes to the backend document with the front end document. If instead, you closed the front end document, saved the backend document and then re-opened the font end document using NotesUIWorkspace.EditDocument, you would still have you attachment.