Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Aug 2002
    Location
    Grand Rapids, Michigan, USA
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change wordmerge source before opening document. (2000)

    I have several word merge letters connected to my access database (different queries), that I want to bring home from the office & take back. The documents are modified from BOTH places. Is there a way IN CODE to change the DataSource of each of the documents, so I don't have to go into each one, have the system error on me & reselect the datasource to the current drive?

    The paths are similar (j:accessdocsdir vs. c:accessdocsdir).

    I do this a LOT, so I want to automate the process. Opening each document has been a real pain.

    Thanks! - Andy

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Change wordmerge source before opening document. (2000)

    Hi Andy,

    The simplest way I know of is to have the paths be identical. To do this, use a batch file to fool your computer into thinking it has a network drive.

    For instance, at my office, our Workgroup templates folder is on the network mapped as the G: drive, as G:Shared

    At home, when my computer starts up it defines the folder which contains a copy of the Shared templates folder as the G: drive. This is done through the DOS subst command which dates back to the days of two-floppy PCs. (Some computers only had one drive - the A: drive but their programs looked for things on the B: drive.)

    The following goes into a text file with the file extension "bat" instead of "txt."

    @echo off
    SUBST J: C:
    exit

    That file (or a shortcut to it) goes in your Start Menu, Programs, Startup folder if you want to have the J: drive whenever you start the computer. Otherwise, it can just go in your start menu and you can run it before you start Word.

    Hope this helps.
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    New Lounger
    Join Date
    Aug 2002
    Location
    Grand Rapids, Michigan, USA
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still need help.

    I'd actually tried that, but since I take it to other locations as well, it's not really practical. I'd really prefer to do it within VBA code.

    There's got to be a better way... any suggestions?

  4. #4
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Still need help.

    Could you not just trap the error?
    If the file doesn't exist, the code uses the alternative location?

  5. #5
    New Lounger
    Join Date
    Aug 2002
    Location
    Grand Rapids, Michigan, USA
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Still need help.

    Well, I've tried that too. Unfortunately, the Document_Open (or Document_Load) events don't prevent the error from happening when you open it.

    Is there any way to check an unopened document for it's datasource without opening it first?

  6. #6
    New Lounger
    Join Date
    Aug 2002
    Location
    Grand Rapids, Michigan, USA
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Still need help.

    MarkJ solved my problem in the Access forum. But if anyone else needs the code, here it is...

    Function SetDataSource()

    Dim wdApp As New Word.Application
    Dim wdDoc As Word.Document
    Dim strMerge As String
    ' *** If use database as path, use this code
    ' Dim strDatabasePath As String
    ' ***' strDatabasePath = CurrentProject.Path & "" &
    CurrentProject.Name
    Set wdDoc = wdApp.Documents.Open ("f:andytest.doc")
    strMerge = wdDoc.MailMerge.DataSource.Name
    '*** my merge source was a word doc, so i used this
    If strMerge = "d:testsource.doc" Or strMerge = "" Then
    'Empty String means data source is not available
    ' *** this changes the source
    wdDoc.MailMerge.OpenDataSource "c:testsource.doc"
    ' *** this just toggles the word document to show the data instead of just the field codes.
    wdDoc.MailMerge.ViewMailMergeFieldCodes = wdToggle
    wdDoc.Save
    wdDoc.Close
    End If
    wdApp.Quit
    Set wdApp = Nothing

    End Function

Posting Permissions

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