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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging word documents from Access, to open only the current record.

Status
Not open for further replies.

oggstar

Technical User
Sep 8, 2001
18
0
0
AU
I have been able to configure an access form to open a word mail merge document.

The problem is that when the word document opens it opens all 41 records and displays the first mail merged record. I would like the word document to open the record that i am currently in when i click on my button from the Access form.
Ie in record number 23 merges word document to number 23, as opoosed to record number one.

Also is it possible to automatically save the document in a specified folder, C:/work and save it based on a feild name, in the access form. If the field name was 1982 then it would save as C:/work/1982.doc

My current code is listed below.
Any help greatly appreciated.

Private Sub Command117_Click()
On Error GoTo Err_Command117_Click
' Button launches Word and opens a specified document
' And runs an optional macro. the macro could print out the word doc and quit

Dim retval As Variant
Dim DocName, MacroName As String
' Drive and Full path to name and location of Word document
DocName = "E:\mergetemp.doc"

'Optional Macro Name. Note Word Macro name cannot have any spaces in it.
'MacroName = "/M" & "MacroName"

'Note full path to Word including Drive and folder
retval = Shell("C:\Program Files\Microsoft Office\Office\winword.exe" & " " & DocName & MacroName, vbNormalFocus)

Exit_Command117_Click:
Exit Sub

Err_Command117_Click:
MsgBox Err.Description
Resume Exit_Command117_Click

End Sub
 
I think that to achieve what you expect, you have to enter the OLE Automation magic world!

That means that you write VB code within Access procedures that drive an instance of Word the way you want.

A part of the information is in the OLE automation topic in Access help while the information on Word is in the VisualBasic topics in the help for Word.

To have a simpler pavement in your way, add the Word Objects definition:
TOOLS, REFERENCE menus and then check Microsoft Word XX library on - where XX depends on the version of Office
you're using.

To help you, some tips in Microsoft KB:
One very close to your question:
and another one
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top