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

Running a mail merge from Access XP

Status
Not open for further replies.

Orion45

IS-IT--Management
Feb 6, 2002
155
US
I currently have the functionality in my application of allowing the user to select an individual's information and click a Form Letters button. They can then pick from a list of form letters shared on the network. Once they've made a choice they can click the merge button which opens a shared Access file with a view and the chosen document. This was working like a charm in Office 2000 but now we have to switch to XP and the code crashes my PC. The app. has been converted to XP and everything works fine except for this portion. The code keeps saying that it can't find my view. Has anyone had any experience with this? The code is as follows:
Code:
Public Function MergeIt(doc As String)
    Dim objWord As Word.Document
    Dim Duplicate As Access.Application
    Dim Query1 As String
    Dim Query2 As String
    Dim ID As Long
    Dim UN As String
   
    UN = Environ("username")
    ID = [Forms]![ApplicantInformation_form].[sys_PersonInformation_ID]
    Query1 = "SELECT WordMerge_v.sys_PersonInformation_ID, WordMerge_v.Address1, WordMerge_v.Address2, WordMerge_v.City, WordMerge_v.StateCode, WordMerge_v.Zip, WordMerge_v.CurrentFlag, WordMerge_v.FirstName, WordMerge_v.MiddleName, WordMerge_v.LastName,"
    Query2 = " WordMerge_v.CurrentName, WordMerge_v.UserName, WordMerge_v.LName, WordMerge_v.FName, WordMerge_v.MName, WordMerge_v.Title"
    Query2 = Query2 + " FROM WordMerge_v"
    Query2 = Query2 + " WHERE (((sys_PersonInformation_ID)=" & ID & ") and ((UserName)='" & UN & "'));"

    doc = "J:\Letters\" & doc
    Set objWord = GetObject(doc)
    Set Duplicate = GetObject("J:\AppLetters_Xp.mdb")
    
    objWord.Application.Visible = True
    objWord.MailMerge.OpenDataSource Name:="J:\AppLetters_Xp.mdb", SQLStatement:=Query1, SQLStatement1:=Query2, LinkToSource:=True
    
    objWord.MailMerge.Execute
    Duplicate.Quit
    DoCmd.Requery
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top