R
Robertico
Let me explain what i'am doing.
I'd like to use Microsoft Word as a report generator for my database.
(I created a VB6 application that creates and has access to a Microsoft
Access database )
One of my fields contains links to photos (full path). I want to print/save
every record on a new page.
(One photo (with some text) per page in one single document)
I created a Ms Word template with bookmarks (within cells) for my fields and
has access from my VB application to this document.
I create a new page for every new record from my database and use AutoText
to create new Bookmarks.
First question:
If Ms Word is already active, the AutoText fails (Error numer 5825, The
object is removed (translated from Dutch))
What can/must i do to prevent this ? (This error only occurs when Ms Word is
already active)
Second question:
Is it possible to define the photo size in my template. (I has to resize the
original photo to approximately 13 x 17 cm)
When the original photo is 2272x1704 everything goes well. The photo fills
the cell. (about 13x17 cm)
But when the original photo is 800x600, it doesn't fill the cell)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Some code i'am using:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Add(App.Path & "\report.dot")
WordObj.Visible = False
' The code below will place the text/photo in the bookmarked location
'DESCRIPTION
Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="description")
WordRange.InsertAfter rs!description
'PHOTO
Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="photo")
WordRange.InlineShapes.AddPicture Filename:=rs!filename,
LinkToFile:=False, SaveWithDocument:=True
' The code below will go to end of page, create a pagebreak and insert
the AutoText
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
WordDoc.AttachedTemplate.AutoTextEntries("MyAutoText").Insert
Where:=Selection.Range, RichText:=True
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Thanks in advance,
Robertico
I'd like to use Microsoft Word as a report generator for my database.
(I created a VB6 application that creates and has access to a Microsoft
Access database )
One of my fields contains links to photos (full path). I want to print/save
every record on a new page.
(One photo (with some text) per page in one single document)
I created a Ms Word template with bookmarks (within cells) for my fields and
has access from my VB application to this document.
I create a new page for every new record from my database and use AutoText
to create new Bookmarks.
First question:
If Ms Word is already active, the AutoText fails (Error numer 5825, The
object is removed (translated from Dutch))
What can/must i do to prevent this ? (This error only occurs when Ms Word is
already active)
Second question:
Is it possible to define the photo size in my template. (I has to resize the
original photo to approximately 13 x 17 cm)
When the original photo is 2272x1704 everything goes well. The photo fills
the cell. (about 13x17 cm)
But when the original photo is 800x600, it doesn't fill the cell)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Some code i'am using:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Add(App.Path & "\report.dot")
WordObj.Visible = False
' The code below will place the text/photo in the bookmarked location
'DESCRIPTION
Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="description")
WordRange.InsertAfter rs!description
'PHOTO
Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="photo")
WordRange.InlineShapes.AddPicture Filename:=rs!filename,
LinkToFile:=False, SaveWithDocument:=True
' The code below will go to end of page, create a pagebreak and insert
the AutoText
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
WordDoc.AttachedTemplate.AutoTextEntries("MyAutoText").Insert
Where:=Selection.Range, RichText:=True
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Thanks in advance,
Robertico