If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Access to Word Mail Merge
I have an Access db that currently is the data source for a mail merged Word
doc. The user presses a button on the Access form to take them directly to the mail merged document, here is the code: Private Sub Command125_Click() Set appWd = CreateObject("Word.Application") appWd.Visible = True appWd.Documents.Open FileName:="I:\groups\PAYROLL\Payroll_Renwals\RENEW-LETTER-sef.docx" End Sub The Word doc opens just fine, however it does not automatically link to the saved data source (in this case a table from the database), so the user has to manually select the data source in order to update the information. Is there a way to link out to this Word doc from Access, opening the document with the data source in tact? |
#2
|
|||
|
|||
Access to Word Mail Merge
Was the document saved with the data source attached to it?
The following is cobbled up from the Word VBA help file to show how to attach the data source to the document if all else fails. Private Sub Command125_Click() Set appWd = CreateObject("Word.Application") appWd.Visible = True Set docnew = appWd.Documents.Open("I:\groups\PAYROLL\Payroll_Re nwals\RENEW-LETTER-sef.docx") With docNew.MailMerge .MainDocumentType = wdFormLetters .OpenDataSource _ Name:="C:\Program Files\Microsoft Office" & _ "\Office\Samples\Northwind.mdb", _ LinkToSource:=True, AddToRecentFiles:=False, _ Connection:="TABLE Orders" End With End Sub -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Decembersonata" wrote in message news I have an Access db that currently is the data source for a mail merged Word doc. The user presses a button on the Access form to take them directly to the mail merged document, here is the code: Private Sub Command125_Click() Set appWd = CreateObject("Word.Application") appWd.Visible = True appWd.Documents.Open FileName:="I:\groups\PAYROLL\Payroll_Renwals\RENEW-LETTER-sef.docx" End Sub The Word doc opens just fine, however it does not automatically link to the saved data source (in this case a table from the database), so the user has to manually select the data source in order to update the information. Is there a way to link out to this Word doc from Access, opening the document with the data source in tact? |
#3
|
|||
|
|||
Access to Word Mail Merge
So I used the code as follows:Private Sub Command125_Click()
Set appWd = CreateObject("Word.Application") appWd.Visible = True Set docnew = appWd.Documents.Open("I:\groups\PAYROLL\Payroll_Re nwals\RENEW-LETTER-sef.docx") With docnew.MailMerge .MainDocumentType = wdFormLetters .OpenDataSource _ Name:="I:\groups\dar\GPROC\PAYROLL\Payroll_The_Hea ly\TheHealy.accdb", _ LinkToSource:=True, AddToRecentFiles:=False, _ Connection:="aa_renewals" End With End Sub However, it then gives me an error message that says: "Run-time error '5174': This file could not be found (I:groups...) I checked the path and it is accurate and will open with other code. Am I missing something in my translation of the code? "Doug Robbins - Word MVP" wrote: Was the document saved with the data source attached to it? The following is cobbled up from the Word VBA help file to show how to attach the data source to the document if all else fails. Private Sub Command125_Click() Set appWd = CreateObject("Word.Application") appWd.Visible = True Set docnew = appWd.Documents.Open("I:\groups\PAYROLL\Payroll_Re nwals\RENEW-LETTER-sef.docx") With docNew.MailMerge .MainDocumentType = wdFormLetters .OpenDataSource _ Name:="C:\Program Files\Microsoft Office" & _ "\Office\Samples\Northwind.mdb", _ LinkToSource:=True, AddToRecentFiles:=False, _ Connection:="TABLE Orders" End With End Sub -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Decembersonata" wrote in message news I have an Access db that currently is the data source for a mail merged Word doc. The user presses a button on the Access form to take them directly to the mail merged document, here is the code: Private Sub Command125_Click() Set appWd = CreateObject("Word.Application") appWd.Visible = True appWd.Documents.Open FileName:="I:\groups\PAYROLL\Payroll_Renwals\RENEW-LETTER-sef.docx" End Sub The Word doc opens just fine, however it does not automatically link to the saved data source (in this case a table from the database), so the user has to manually select the data source in order to update the information. Is there a way to link out to this Word doc from Access, opening the document with the data source in tact? |
#4
|
|||
|
|||
Access to Word Mail Merge
I figured it out. Instead of trying to open the Word document containing the
mail merge, I instead coding in to have it follow a hyperlink. When it follows the hyperlink the data source remains in tact. The code, for anyone interested, is: Private Sub Command125_Click() Dim ObjectApp As Object Dim strLinkUrl As String Dim strPath As String Set objApp = CreateObject("Word.Application") objApp.Visible = True objApp.Application.WindowState = wdWindowStateMaximize objApp.Application.Activate ' for a subdirectory located in the same directory ' as the database: objApp.Visible = True objApp.Application.Activate strPath = Access.Application.CurrentProject.Path & "\" strLinkUrl = strPath & "RENEW-LETTER-sef.docx" Me.Command125.HyperlinkAddress = strLinkUrl End Sub "Doug Robbins - Word MVP" wrote: Was the document saved with the data source attached to it? The following is cobbled up from the Word VBA help file to show how to attach the data source to the document if all else fails. Private Sub Command125_Click() Set appWd = CreateObject("Word.Application") appWd.Visible = True Set docnew = appWd.Documents.Open("I:\groups\PAYROLL\Payroll_Re nwals\RENEW-LETTER-sef.docx") With docNew.MailMerge .MainDocumentType = wdFormLetters .OpenDataSource _ Name:="C:\Program Files\Microsoft Office" & _ "\Office\Samples\Northwind.mdb", _ LinkToSource:=True, AddToRecentFiles:=False, _ Connection:="TABLE Orders" End With End Sub -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "Decembersonata" wrote in message news I have an Access db that currently is the data source for a mail merged Word doc. The user presses a button on the Access form to take them directly to the mail merged document, here is the code: Private Sub Command125_Click() Set appWd = CreateObject("Word.Application") appWd.Visible = True appWd.Documents.Open FileName:="I:\groups\PAYROLL\Payroll_Renwals\RENEW-LETTER-sef.docx" End Sub The Word doc opens just fine, however it does not automatically link to the saved data source (in this case a table from the database), so the user has to manually select the data source in order to update the information. Is there a way to link out to this Word doc from Access, opening the document with the data source in tact? |
Thread Tools | |
Display Modes | |
|
|