Results 1 to 2 of 2
  1. #1
    Join Date
    May 2005
    Posts
    2

    Merge Code problems

    I am trying to merge data entered on a form with an existing word doc and am running into trouble. My code is:

    Function MergeIt()
    Dim HoldNotice2 As Word.Document
    Set HoldNotice2 = GetObject("C:\Documents and Settings\kfergus\Desktop\HoldNotice2merge.doc", "Word.Document")

    HoldNotice2.Application.Visible = True
    HoldNotice2.MailMerge.OpenDataSource _
    Name:="C:\Documents and Settings\kfergus\desktop\hold.mdb ", _
    LinkToSource:=True, _
    Connection:="TABLE Holdtbl", _
    SQLStatement:="SELECT * FROM [Holdtbl]"



    HoldNotice2.MailMerge.Destination = wdSendToNewDocument
    HoldNotice2.MailMerge.Execute
    HoldNotice2.Application.Options.PrintBackground = False
    HoldNotice2.Application.ActiveDocument.PrintOut

    HoldNotice2.Close

    End Function

    1/2 the time it works and the other 1/2 I get error messages about the db being unable to open or to be locked. When I debug it's always the same lines that I'm having trouble with, Set HoldNotice2... and HoldNotice2.MailMerge.OpenDataSource ... I verified the location and it's correct.

    Help, please!

  2. #2
    AndrewAfresh is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2006
    Posts
    21
    1) when the code is running, do you have any forms open which could be locking the database? if so, see if you can close them or ensure that they are refreshed before the merge runs.

    2) if you want, i could post some code which i have used to do mail merges - it exports the data as a text file and then gets word to do the merge on that text file instead directly on the database, so it could get round your locking prob.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form Combo problems
    By Honeytree in forum Forms
    Replies: 0
    Last Post: 10-05-2008, 01:32 PM
  2. DSUM Problems
    By swampdonkey in forum Forms
    Replies: 2
    Last Post: 09-29-2006, 10:52 AM
  3. Mail merge
    By grgerhard in forum Forms
    Replies: 0
    Last Post: 04-25-2006, 05:06 PM
  4. Mail Merge problem
    By kfergus in forum Programming
    Replies: 0
    Last Post: 04-24-2006, 01:06 PM
  5. Problems with a query in a list box
    By admaldo in forum Forms
    Replies: 1
    Last Post: 04-05-2006, 05:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums