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

    Change Word DataSources without opening document (Access2000)

    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
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change Word DataSources without opening document (Access2000)

    You could store the paths in a table with just 2 fields and 1 record. Then use a combobox (or similar control) to switch between the two. Instead of explicitly entering a pathname, use the combobox's value as the pathname.

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

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

    Re: Change Word DataSources without opening document (Access2000)

    But that doesn't really help me. The moment the word document is opened, it says the original data cannot be found. Then the user has to remove the data source header info in order to continue. If you tell it not to remove the source, the document closes.

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change Word DataSources without opening document (Access2000)

    Ahh, I see... I thought you had the Word mailmerge automated from within Access.

    There are probably better ways to do this, but my suggestion would be to place some code in the Document_Open event of the Word Document to check for the existance of the data source (MailMerge.DataSource.Name). If it's not there, you could have the user enter the file/path name in an Input Box for the Name argument of the MailMerge.OpenDataSource method.

    You may want to post this in the Word forum. The folks there will be a little quicker with the specific Word issues than those of us who lean towards Access.

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

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

    Re: Change Word DataSources without opening document (Access2000)

    I tried that, but had the same results. Apparently, the Document_Open property doesnt prevent the document from loading. I tried a Document_Load event, too.

    Is there any way to check a document's datasource property without actually opening the document? <img src=/S/frown.gif border=0 alt=frown width=15 height=15>

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change Word DataSources without opening document (Access2000)

    Checking the data source of a mail merge without opening the document should be possible in a behind-the-scenes manner using VBA. However, (and keep in mind that I'm not a Word expert) I don't think there's a way to read that information from a document without making it the Active Document in a VBA environment.

    You could try something like this (be sure that Word 9.0 is checked in the References - under Tools|References in VBA):<pre>Function SetDataSource()
    Dim wdApp As New Word.Application
    Dim wdDoc As Word.Document
    Dim strMerge As String
    Dim strDatabasePath As String
    strDatabasePath = CurrentProject.Path & "" & CurrentProject.Name


    Set wdDoc = wdApp.Documents.Open("<YourDocumentName")
    strMerge = wdDoc.MailMerge.DataSource.Name
    If strMerge = "" Then 'Empty String means data source is not available
    wdDoc.MailMerge.OpenDataSource strDatabasePath
    wdDoc.Save
    wdDoc.Close
    End If


    wdApp.Quit
    Set wdApp = Nothing
    End Function</pre>

    This assumes that your current database is the data source for the merge. If it's different, you'll need to modify the code. Also, you'll probably need to tweak the OpenDataSource function to include the SQL statements telling it which table/query to use for the data. This should at least point you in the right direction.

    HTH <img src=/S/salute.gif border=0 alt=salute width=15 height=20>

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

    Re: Change Word DataSources without opening document (Access2000)

    Awesome!!! That's exactly what I needed. Thanks a ton!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> - Andy

Posting Permissions

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