jwcolby
jwcolby at colbyconsulting.com
Mon Feb 18 10:56:16 CST 2008
I have been doing a mailmerge using a text file to hold the data to be pulled into the document. I would like to hear about the experiences of anyone who is using a query to pull the data straight out of Access. Does word actually OPEN an instance of Access to do this? Can I feed it a pointer to the already open FE? I was using the following code. I commented out the OpenDataSource line that pulled from a text document and TRIED to use a query directly in the FE. That resulted in locking up the FE. the opensource line never returned. Private Function mMergeWordDoc() As Boolean On Error GoTo Err_mMergeWordDoc Dim AppWord As Object Dim lMerge As Object Dim lDoc As Object Set AppWord = CreateObject("Word.Application") With AppWord .Visible = True .Documents.Open (mclsMMDocName.pLocalFileSpec) Set lMerge = .ActiveDocument.MailMerge 'lMerge.OpenDataSource mclsMMDocName.pLocalDataFileSpec, wdOpenFormatText lMerge.OpenDataSource _ Name:="c:\DISFE\DISCO_FE.mdb", _ LinkToSource:=True, AddToRecentFiles:=False, _ Connection:="QUERY mstrQueryName", _ SQLStatement:="SELECT * FROM [mstrQueryName]" lMerge.Execute Set lDoc = .Documents(.Documents.Count - 1) lDoc.SaveAs mclsMMDocName.pNetworkFileSpec End With mMergeWordDoc = True Exit_mMergeWordDoc: On Error Resume Next AppWord.Quit savechanges:=False Set lMerge = Nothing Set lMerge = Nothing Set AppWord = Nothing Exit Function Err_mMergeWordDoc: LogErr Err.Number, Err.Description, Erl, cstrmodule, "mMergeWordDoc" Resume Exit_mMergeWordDoc Resume 0 '.FOR TROUBLESHOOTING End Function John W. Colby Colby Consulting www.ColbyConsulting.com