Report in MS Word

Hi All,We have 2 modules Employee and Report.In the employee module we have information for each employee including their photographs as attachment.

Now in the report module we have to create a report in which we have to show photograph of each employee as well as their other information.

Report can be in any format : Word or Excel

We have tried creating an HTML report and we have been succesful.

However same thing is not working for MS Word.

Code for HTML report:

While Not( doc Is Nothing)

Print ||

Dim vEval As Variant

vEval = Evaluate(“@AttachmentNames”, doc)

i=0

Forall v In vEval

If v <> “” Then

If (i<1) Then

Set attch = doc.GetAttachment( v)

i=i+1

dbpath = doc.path(0)

docID = doc.UniversalID

serName = doc.serName(0)

viewID=ViewByDocID.UniversalID

imgName = attch.Name

If Not imgName =“” Then

Print || +||

Print ||

End If

Subject: Report in MS Word

Here is an agent I use within a view. It takes the selected document(s) and creates a word document that contains the employees bio and photograph (which was attached). I also start Word’s spell check because users create their own bios and we can’t expect spelling to be right all the time.:slight_smile:

Hope this is of some value in your project too. By the way… when I ask users to attach their photo, within the button I also IMPORT it… so it’s attached and imported into a field. This is so I can display the photo in notes client. If you’d like the code for that piece too, just let me know in your response.

Sub Click(Source As Button)

Dim wdApp      As Variant

Dim docNew   As Variant

Const ERR_APP_NOTFOUND  = 429

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments



On Error Resume Next	

Set wdApp = CreateObject("Word.Application")

If Err = ERR_APP_NOTFOUND Then

	Msgbox "Word isn't installed on this computer. " 

	Set wdApp = Nothing

	Exit Sub

End If

Set docNew = wdApp.Documents.Add()



If ( collection.Count < 1 ) Then

	Set wdApp = Nothing

	Msgbox "Please Select Documents"

End If





Dim object As NotesEmbeddedObject





For i = 1 To collection.Count

	Set doc = collection.GetNthDocument( i )

	filecounter = 0

	

	filenames=Evaluate("@AttachmentNames",doc)

	Set object = doc.GetAttachment( filenames(filecounter) )

	filenames=Evaluate("@AttachmentNames",doc)

	numberoffiles=Evaluate("@Attachments",doc)

	If numberoffiles(0)>0 Then

		For filecounter=0 To numberoffiles(0)-1

			Print filenames(filecounter)

			Set object = doc.GetAttachment( filenames(filecounter) )

			If ( object.Type = EMBED_ATTACHMENT ) Then

’ fileCount = fileCount + 1

				Call object.ExtractFile ("c:\"+ filenames(filecounter) ) ' extract file

				wdApp.Selection.TypeText " "

				wdapp.Selection.InlineShapes.AddPicture "c:\"+ filenames(filecounter) ' bring into word

				wdApp.Selection.TypeText " "

				wdApp.Selection.TypeParagraph

				Kill "c:\"+ filenames(filecounter) 'garbage collection

			End If

		Next filecounter

	End If

	

	

	

	My_Header=doc.GetItemValue( "First_Name" )(0) + " " + doc.GetItemValue( "Last_Name")(0)

	My_Title=doc.GetItemValue( "Title")(0)

	My_text=doc.GetItemValue( "Body")(0)

’ Add text to document.

	wdApp.Selection.TypeText My_Header + Chr(13) + My_Title + Chr(13) + My_text + Chr(13)+ Chr(13) + Chr(13)+ Chr(13)

	wdApp.Selection.TypeText " "

	wdApp.Selection.TypeParagraph

Next



wdApp.Selection.WholeStory

wdApp.Selection.Font.Name="Garamond"

wdApp.Selection.Font.Size=10

wdApp.visible = True		

wdApp.Selection.Range.CheckSpelling

End Sub

Subject: Report in MS Word