I have a database which acts as a link to word\excel files held on our
server file system.
I have written the following code to access these word\excel files and
create a new Notes document with these files attached to the "Body"
field of the document.
The script unfortunately only works when it is debugged and all the
lines are stepped through.
If it is not debugged the attached files do not end up in the "Body"
field
Has any body got any ideas??
Dim workspace As New notesuiworkspace
Dim session As New notessession
Dim db As NotesDatabase
Dim view As NotesUIView
Dim ndc As NotesDocumentCollection
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Set db = session.CurrentDatabase
Set view = workspace.CurrentView
Set ndc = view.Documents
dcount = ndc.Count
dcount = Cstr(dcount)
If dcount = "0" Then
Messagebox"You have not selected any documents",48,"Stop"
Exit Sub
End If
Set doc = ndc.getfirstdocument
Dim ndoc As notesdocument
Dim nview As notesview
Dim cdoc As New notesdocument(db)
Dim rtitem As NotesRichTextItem
REM Set rtitem = New notesrichtextitem(uidoc,"Body")
Set rtitem = New NotesRichTextItem( cdoc, "Body" )
cdoc.form = "Record"
cdoc.primarycode = "E"
cdoc.prefix = "E"
cdoc.docissue = "N/A"
Dim attachedfile As NotesEmbeddedObject
firstline = "Please find files attached. " & Chr(10) & Chr(10)
Call rtitem.appendtext(firstline)
Do While Not (doc Is Nothing)
primarycode = doc.primarycode(0)
If primarycode <> "E" Then
filelocation = Cstr(doc.filelocation(0))
recordnum = doc.projectnumber(0) & doc.prefix(0) &
doc.recordnumber(0)
nextline = recordnum & Chr(10)
cf = Dir(filelocation,0)
If cf <> "" Then
Set attachedfile =
rtitem.embedobject(EMBED_ATTACHMENT,"",filelocation)
Else
Messagebox"Cannot find file associated with record " & recordnum &
" email will be created without this file attached.",64,"Attach Error"
End If
Else
Messagebox"You have selected an email to be attached, this cannot
be performed. Script will continue",64,"Attach Error"
End If
Set doc = ndc.getnextdocument(doc)
Loop
Call workspace.editdocument(True,cdoc)