![]() |
#1
|
|||
|
|||
![]()
I'm debugging an application at the moment where a colleague of mine created a method that iterates through all record sets and turns them into tables in a .docx document.
Something goes horribly wrong when creating a document for a large dataset, though. Here's the code: Code:
With objWord.Selection .Find.Execute While .Find.Found 'Set the size and font for the entire selection .Font.Name = "Calibri" .Font.Size = 10 rsPDA.MoveFirst While Not rsPDA.EOF 'Header above a series of tables If sLeefdomein <> rsPDA.value("Leefdomein") Then sLeefdomein = rsPDA.value("Leefdomein") .Font.Size = 12 .Font.Bold = True .TypeText Text:=vbNewLine + sLeefdomein .Font.Size = 10 .Font.Bold = False End If 'Create new table Set t = objWord.ActiveDocument.Tables.Add(Range:=objWord.Selection.Range, _ NumRows:=5, _ NumColumns:=6, _ DefaultTableBehavior:=wdWord9TableBehavior, _ AutoFitBehavior:=wdAutoFitWindow) 'Define columns t.Cell(1, 2).Merge MergeTo:=t.Cell(1, 6) t.Cell(2, 2).Merge MergeTo:=t.Cell(2, 6) t.Cell(3, 2).Merge MergeTo:=t.Cell(3, 6) t.Cell(4, 2).Merge MergeTo:=t.Cell(4, 6) 'Insert data t.Cell(1, 1).Range.Text = "Probleem": t.Cell(1, 1).Range.Font.Italic = True t.Cell(1, 2).Range.Text = rsPDA.value("Probleem") t.Cell(2, 1).Range.Text = "Doel": t.Cell(2, 1).Range.Font.Italic = True t.Cell(2, 2).Range.Text = rsPDA.value("Doel") t.Cell(3, 1).Range.Text = "Actie": t.Cell(3, 1).Range.Font.Italic = True t.Cell(3, 2).Range.Text = rsPDA.value("Actie") t.Cell(4, 1).Range.Text = "Uitvoering": t.Cell(4, 1).Range.Font.Italic = True t.Cell(4, 2).Range.Text = rsPDA.value("Uitvoering") t.Cell(5, 1).Range.Text = "Prob. eval. ": t.Cell(5, 1).Range.Font.Italic = True t.Cell(5, 2).Range.Text = rsPDA.value("DatumProbleemEvaluatie") t.Cell(5, 3).Range.Text = "Actie evaluatie ": t.Cell(5, 3).Range.Font.Italic = True t.Cell(5, 4).Range.Text = rsPDA.value("DatumAktieEvaluatie") t.Cell(5, 5).Range.Text = "Tijd ": t.Cell(5, 5).Range.Font.Italic = True t.Cell(5, 6).Range.Text = rsPDA.value("Tijd") Set t = Nothing 'Destroy table reference. 'Set cursor for next while loop .MoveDown Unit:=wdLine, Count:=5 .TypeText Text:=vbNewLine Sleep 100 'Even 1000 doesn't change anything. rsPDA.MoveNext Wend .Find.Execute Wend ![]() All goes well until page 7 or 8 (no matter what's in the dataset). I was thinking maybe the WordObjects Tables.Add method is working async behind the scenes and this code pumps the next table into it's rendering engine too quickly? But I'm not sure because a sleep on 100, 250 and 1000 didn't event change the position where the tables started to nest. Any help or tips would be appreciated. |
#2
|
|||
|
|||
![]()
Nevermind, got it!
I had to move to the end of the document (.MoveEnd) before moving to a new line. That fixed it!!! |
![]() |
Tags |
tables;formula;automating, vb6 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Powerpoint adding '1' to end of text for no reason? | LKS | PowerPoint | 0 | 05-16-2013 09:40 AM |
![]() |
Guy Roth | Word | 12 | 12-05-2012 08:44 AM |
Any possible reason template is not saved upon exiting? | New Daddy | Word | 3 | 10-17-2012 01:51 PM |
![]() |
Wyskers | Word | 1 | 11-13-2011 05:43 AM |
Word 2003. Is there a reason I can't put images in the footer? | cheesysocks | Drawing and Graphics | 2 | 02-19-2010 06:16 AM |