Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Jan 2004
    Location
    Derry, Derry, Ireland, Northern
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automate Word XP from Access XP (Access XP)

    Hi folks,

    I have borrowed some code from Helen Feddema (thanks!) that lets me open Word, and depending on the value of a label caption either open a blank doc or open an existing doc set to a certain data source for merge purposes.

    All works exactly as expected in A2000/Word2000, but when I move to a machine running Access XP and Word XP the code falls down. It says that there has been a database dialog error, and then it says Word cannot open the specified file.

    When i go to task manager,however, I can see that an invisible instance of Word is open, and by looking in the folder that the document is locate din, I see a temp file associated with that doc, so I suspect that Word is a) open and [img]/forums/images/smilies/cool.gif[/img] able to open the file but then something trips it up.

    Any clues as to any changes from 2000 to XP that may cause this?

    Thanks in advance..

    The code in question.

    Dim str_sql As String
    Dim strfile As String
    'Dim wdnewblankdocument
    strfile = Me.lblDocLoc.Caption
    str_sql = "select * from tblSourceData;"
    Dim db As Database
    Set db = CurrentDb
    'create instance of word
    On Error GoTo ErrorHandler
    Dim pappword
    'Set pappword = GetObject(, "Word.Application") - changed this on 2 apr 04
    'word was not made active if word was already open
    Set pappword = CreateObject("Word.Application")
    pappword.Visible = True
    'open the required doc - either blank or the chosen doc
    If strfile = "" Or strfile = "-Click 'Browse' to select a document to use for this merge.-" Then 'open a blank doc
    'open a blank doc
    pappword.Documents.Add
    Else
    'open the file
    pappword.Documents.Open strfile
    End If
    'create sql string and set document mail merge source to that data
    pappword.ActiveDocument.MailMerge.OpenDataSource _
    Name:=db.Name, Sqlstatement:=str_sql
    pappword.Visible = True
    Set pappword = Nothing
    Exit Sub
    ErrorHandler:
    'Word is not running; open Word with CreateObject
    If Err.Number = 429 Then
    Set pappword = CreateObject("Word.Application")
    pappword.Visible = True
    Resume Next
    Else
    MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
    Set pappword = Nothing
    Exit Sub
    End If

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Automate Word XP from Access XP (Access XP)

    Mail merge has changed radically from Word 2000 to Word 2002 (aka XP). Until Word 2000, DDE was the default method of connecting to an Access data source, starting with Word 2002 it is OLE DB. The "old" code does not work with OLE DB. To get the original behavior, you must add an argument to OpenDatasource:

    pappword.ActiveDocument.MailMerge.OpenDataSource _
    Name:=db.Name, Sqlstatement:=str_sql, SubType:=wdMergeSubTypeWord2000

  3. #3
    Lounger
    Join Date
    Jan 2004
    Location
    Derry, Derry, Ireland, Northern
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automate Word XP from Access XP (Access XP)

    Hans,

    Thanks for that - I won't be able to test for a few days, I'll keep you posted.

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Automate Word XP from Access XP (Access XP)

    As Hans notes, things changed drastically from Word 2000 to Word 2002 - you might find this Woody's Access Watch article informative - we also have a Word Merge Tutorial that includes a number of other references.
    Wendell

  5. #5
    Lounger
    Join Date
    Jan 2004
    Location
    Derry, Derry, Ireland, Northern
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automate Word XP from Access XP (Access XP) -s

    Hi all,

    Thanks for your help. I'm deploying this to users who have Office 2000 and Office 2002, so I needed to capture the error. I had thought to try and establish which version of Access was being used by each user, but instead I set it up to use Office 2002 notation with the aforementioned "SubType:=wdMergeSubTypeWord2000" thingy, which works fine in A2002, but throws up error number 448 in Office 2000, so i trap that error and reset the merge data source without the SubType:=wdMergeSubTypeWord2000 thingy.

    Works like a charm.

    Thanks for all the hints, tips and links.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •