Successful Dynamic Table Resizing from Notes To Word

Thought someone might find this useful so I figured I would share. I have an application that needs a solid “Export To Word” function. I thought about simpler ways but none worked. I have an embedded view that I need to format and sit nicely in the word document. The edit menu selection “Copy Selected As Table” would have worked great, but there was no way to access it programmatically. So I have a word template and I created fields within it and went through a notes view entry collection gathering up all of the documents that are within the embedded view, (in a single category based upon the unique ID of the parent, or the current UI document). I was parsing back through the arrays writing the values out to the fields in word when I got a “String too long” error from wht word object. Can’t get a break here. Well, all of the individual fields are one or two characters, except a field for descriptions. This array was causing the word document field object to bomb usually by the second iteration. Anyway, I added a table to the template, point my position at that table, and dynamically add rows with text to that table as I parse throught the entries of the collection…this is a stripped down version that just outlines the approach for adding rows to a table in word based upon notes data:

Set db = session.CurrentDatabase

Set view = db.GetView("lineItemEntries")

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document



uniqID = doc.UniversalID	



Set vc = view.GetAllEntriesByKey(uniqID)

Set entry = vc.GetFirstEntry()

docCount = vc.count

Set word = CreateObject(“Word.Application.9”) 'Create Word object

Call word.documents.add("c:\lotus\notes\data\BOM.dot") 'Create a new document based on the template "<name>.Dot"

Set worddoc = word.activedocument 'Get a handle for the active document

With worddoc

 Dim tableobj As Variant	

	Dim j As Integer

	Dim k As Integer

'this object has count properties for dynamic stuff -- not needed here

	Set tableobj = .Tables(2)		

	

	Set entry = vc.GetFirstEntry()

	

	Call tableobj.cell(1,1).select	

	Call word.selection.typetext("Descriptions of Items Listed Above:")	

	j=2

	k=1

	For k = 1 To docCount

		Call tableobj.Rows.Add()

		Set entryDoc = entry.Document	

		Call tableobj.cell(j,1).select			

		temp = entryDoc.partNumber(0) & " - - " & entryDoc.description(0)			

		Call word.selection.typetext(temp)			

		Set entry = vc.GetNextEntry(entry)			

		j=j+1			

	Next k	

	End With