Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


"Mail Merge" from VB to Word

Posted on 1999-09-10
Medium Priority
Last Modified: 2010-05-02
I have an application that needs to publish results in MS Word in a "Mail Merge" type activity.  Insert fields in a template document which only outputs a selected recordset or single record.  Do I use the Shell command for this, or is there a way to publish a SQL statement that would accomplish this.  (This is easily performed in Access, is it similiar type commands?)

Database: MS Access 97

Application: VB 6.0

Details: Single form brings up a single record.  Send that record to an already made word document with insert fields that need data from the VB form.

Question by:JimBre
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Author Comment

ID: 2038581
Edited text of question.

Accepted Solution

tcurtin earned 400 total points
ID: 2038665
Hi JimBre,
Set the document up with bookmarks in strategic locations.
Set a reference to Word.
Dim oWord as Word.Application
Set oWord = new Word.Application
dim odoc as Document
Set oDoc = oWord.Documents.Open("c:\MyFormLetter.Doc")
with oDoc
    .Range.Bookmarks("CustomerName")= txtCustName.text
    'and so on.
    .Close False 'don't save
end with
You can set the visible property if you need to see it.


Author Comment

ID: 2038826
Appreciate the response.  It was clear and very easy to follow.


Author Comment

ID: 2048391
I attempted the response that tcurtin gave, (and yes I was sure to add the appropriate references) and I get an "Invalid object" message when I attempt to run it.  It specifically highlights the ".Range.Bookmarks("Bookmark Name")= Control.Text"  Is there something I'm missing?  Is there a better way?  'Who invented liquid soap and why?'

Appreciate the help.

Expert Comment

ID: 6868166
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.
Thank you,
Moderator @ Experts Exchange

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question