Guest_imported
New member
- Jan 1, 1970
- 0
Hello,
I have a desktop application that outputs around 800+ variables (mostly strings, but some graphics) that I need to merge with a Word template so that users can print various documents. I have to use an intermediate file (not manipulate Word from the desktop app) as the data source for the merge, and am trying different types to see which is best (.txt. mdb. .db), but all are creating problems particularly in relation to the graphics elements.
I've got a wee module below, in Access, that takes a simple table (with .wmf files) and dumps the contents into Word, and it works grand, and I get all excited, but when I try the same code in VB (to remove the Access element so that I have a standalone module to do the manipulating), nothing happens. Zippo. Is there something wrong with the way I've done the code, or am I barking up the wrong tree entirely, and there's a better way to go about this?
Any help or thoughts or comments would be appreciated.
Thanking you
Mars
Set ws = DBEngine.WorkSpaces(0)
Set db = ws.OpenDatabase _
("D:\PK\Sample.mdb", False, False, "MS Access;PWD="
Set rst = db.OpenRecordset("sample"
Set obj = CreateObject("Word.Application"
obj.Application.Visible = True
rst.MoveFirst
obj.Documents.Add Template:="C:\Windows.000\Application Data\Microsoft\Templates\Dot1.dot", NewTemplate:=False
Do While Not rst.EOF
With obj
.Selection.TypeText Text:="" & rst![Description]
.Selection.InlineShapes.AddPicture FileName:="" & rst![Picture], _
LinkToFile:=False, SaveWithDocument:=True
.Selection.TypeText Text:=Chr(13) 'New Line.
.Selection.InsertBreak Type:=3 'wdSectionBreakContinuous.
End With
rst.MoveNext
Loop
End Function
I have a desktop application that outputs around 800+ variables (mostly strings, but some graphics) that I need to merge with a Word template so that users can print various documents. I have to use an intermediate file (not manipulate Word from the desktop app) as the data source for the merge, and am trying different types to see which is best (.txt. mdb. .db), but all are creating problems particularly in relation to the graphics elements.
I've got a wee module below, in Access, that takes a simple table (with .wmf files) and dumps the contents into Word, and it works grand, and I get all excited, but when I try the same code in VB (to remove the Access element so that I have a standalone module to do the manipulating), nothing happens. Zippo. Is there something wrong with the way I've done the code, or am I barking up the wrong tree entirely, and there's a better way to go about this?
Any help or thoughts or comments would be appreciated.
Thanking you
Mars
Set ws = DBEngine.WorkSpaces(0)
Set db = ws.OpenDatabase _
("D:\PK\Sample.mdb", False, False, "MS Access;PWD="
Set rst = db.OpenRecordset("sample"
Set obj = CreateObject("Word.Application"
obj.Application.Visible = True
rst.MoveFirst
obj.Documents.Add Template:="C:\Windows.000\Application Data\Microsoft\Templates\Dot1.dot", NewTemplate:=False
Do While Not rst.EOF
With obj
.Selection.TypeText Text:="" & rst![Description]
.Selection.InlineShapes.AddPicture FileName:="" & rst![Picture], _
LinkToFile:=False, SaveWithDocument:=True
.Selection.TypeText Text:=Chr(13) 'New Line.
.Selection.InsertBreak Type:=3 'wdSectionBreakContinuous.
End With
rst.MoveNext
Loop
End Function