Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report Generator in Word

Status
Not open for further replies.

Elena

Technical User
Oct 20, 2000
112
US
I am trying to create a report generator that opens and fills in a Word Form automatically with data from Visual Basic controls. First, how do I open the file from VB? Second, can I use SetFormResult from VB? I already have a makeshift version in WordBasic, but it isn't very friendly.

Any help is appreciated.

Thanks,
Elena

BTW - I know this answer is in here somewhere, but the keyword search is down at the moment. Please forgive me if this seems like a silly question.

 
I'm not sure about SetFormResult, but I have written a program that opens up a word doc, fills in pre-set fields, and saves the document. You can set a reference to Microsoft Word 9.0 Object Library which gives you reference to MS Word controls. From there, you can dim a new word application and document. Then, you can set up a Word Template and insert "Bookmarks" where you want to populate data to. In the code, include a statement like:

wrdDoc.Bookmarks("CustomerName").Range.Text = bkm1

where wrdDoc is your dimmed document and bkm1 is your string of data.

By the way, here is how to dim and open a word doc:

Dim wrdDoc As Word.Document
Dim wrdApp As Word.Application

Set wrdApp = New Word.Application
Set wrdDoc = wrdApp.Documents.Add
("M:\Word\ExampleTemplate.doc")

I hope this helps a little and that I understood your question.
 
Hello,

I have figured out most of the answers for this one on my own, but I thought it would be helpful to other readers if I posted the answers. Hope it helps someone else.

To open a document in Word (runtime):

Dim wdApp as Object
Set wdApp as CreateObject("Word.Application")
With wdApp
.Document.Open "Filename"

THEN to set a FormField Result (Still under With wdApp)

.ActiveDocument.FormFields("FieldName").Result = string
>> or for Combo Box Fields <<
.ActiveDocument.FormFields(&quot;FieldName&quot;).DropDown.Value = index#
>> For CheckBoxes <<

.ActiveDocument.Formfields(&quot;FieldName&quot;).Checkbox.Value = True

Thanks to those who responded to the original question.

Elena


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top