I am trying to control the input of data into a Word 97 document using a VB form to collect the data. How do I then best transfer this data into the correct locations on the document.

Dani AI

Generated

Two practical approaches will solve this. One is the batch route hinted at (store form values in a data source and use Word mail merge when you need many letters/documents). The other is direct automation from your VB form into a single Word template using bookmarks or legacy form fields — this is usually simpler for one-off or interactive documents. The VB TextBox ControlSource cannot be pointed at a Word bookmark; you must copy values in code.

A minimal VB6 pattern (early binding) looks like this — open the template, write into a bookmark range, re-add the bookmark (assigning text removes the bookmark), save and close:

' VB6, early-binding example (add Microsoft Word Object Library reference)
Dim appWord As Word.Application
Dim doc As Word.Document
Dim rng As Word.Range

Set appWord = New Word.Application
Set doc = appWord.Documents.Open("C:\Template.doc")
Set rng = doc.Bookmarks("ClientName").Range
rng.Text = Me.txtClientName.Text
doc.Bookmarks.Add "ClientName", rng

doc.SaveAs "C:\Output.doc"
doc.Close False
appWord.Quit
Set rng = Nothing
Set doc = Nothing
Set appWord = Nothing

Notes and troubleshooting:

  • Use simple bookmark names (alphanumeric, no spaces) and match them exactly.
  • For fillable Word form fields use doc.FormFields("FieldName").Result = value instead.
  • If deploying to different Office versions, prefer late binding (CreateObject("Word.Application")) to avoid reference issues.
  • Always close documents and quit Word or you’ll leave WINWORD.EXE processes running.

If the need is many personalized docs, push your form data into Access or CSV and run a mail merge; if you want interactive, single-document editing, automate bookmarks/formfields from VB as shown.

Recommended Answers

All 5 Replies

do you have microsoft access?

I have office 97 profesional so yes and VB6. The text box on the VB form has a control source property, how can I link this to a location on the Word document (maybe a bookmark?).

you could get the form to put data into an access database then mail merge it from there into a word document?

Thank you I will look into that. I am not familiar with mail merging.

mail merge is where you have a word document that gets data from an access database


e.g

<address>

mr <name> you are in debt of <balance> to our company. please pay within 28 days or your account will be closed


Mail merge will make a document like that for every record

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.