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!

Mailmerge Opens another Session of Access

Status
Not open for further replies.

MyDugs

Technical User
Oct 2, 2001
10
GB
Hi there,

I am doing a mailmerge from Access97 to Word97 using routine shown in MSN.
I have tried the solution shown in FAQ where I reinstate the Microsoft Access application title, indeed have tried it on a version where app title hasn't been modified at all.
But still get Access opening up again when Word97 is activated.

Can live with it but niggles, so any help greatly appreciated. Dave
 
Thanks vr,

adh_accOfficeGetFileNameInfo is a function from Developer's Handbook capturing chosen document from directory to merge.
I want Word to open as it is without going straight into Print so as the operator can proof read it prior to printing.

Function MergeIt()
Dim letter As String
Dim gfni As adh_accOfficeGetFileNameInfo
Dim objWord As Word.Document
Dim intx As Integer
Dim vexit

On Error GoTo Merge_Err

intx = DCount("[Supporter ID]", "tblTemp")
If intx > 0 Then
vexit = MsgBox("This will MAILMERGE the selected " & intx & " records." _
& Chr(13) & Chr(10) & "Do you wish to continue ?", 273, "MAILMERGE")
If vexit = vbCancel Then
Call warn_on
MsgBox "Mailmerge CANCELLED !", 64, "CANCEL"
Exit Function
End If

With gfni
.hwndOwner = Application.hWndAccessApp
.strAppName = ""
.strDlgTitle = "Select a Letter to MERGE"
.strOpenTitle = "Mail Merge"
.strFile = ""
.strInitialDir = "C:\my documents\scha\database\letters"
.strFilter = "(*.doc)"
.lngFilterIndex = 1
.lngView = adhcGfniViewList
.lngFlags = adhcGfniNoChangeDir Or adhcGfniInitializeView
End With

If adhOfficeGetFileName(gfni, True) = adhcAccErrSuccess Then

Set objWord = GetObject(Trim(gfni.strFile), "Word.Document")

objWord.Application.Visible = True

objWord.MailMerge.OpenDataSource _
Name:="C:\My Documents\SCHA\Database\Mailing Database.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblTemp", _
SQLStatement:="Select * from [tblTemp]"

objWord.MailMerge.Execute

DoCmd.RunSQL "UPDATE tblMailer SET tblMailer.letterflag = True;"


End If
Else
MsgBox "There are no Records selected to Print", vbOKOnly, "No Records Matched"
Exit Function

End If

Merge_Exit:
Exit Function

Merge_Err:
DoCmd.Hourglass False
DoCmd.SetWarnings True
Resume Merge_Exit

End Function Dave
 
Well, I only see a few differences between your code and mine.

The line: objWord.MailMerge.OpenDataSource_
Name:="c:\My Documents...
may be causing the problem.

Try setting the datasource in the Word document under the Tools, MailMerge, Create Datasource

Seems to work for me.

Good luck!

 
Thanks vr, but 'nae luck' so to speak.
Blocked out that part of code and set data source direct in the document but the same thing happens.

If I open the document direct from Word then all is ok, but when trying to run it from Access always opens another version of the application.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top