lparameters nScopeOption && 1-Thisform.rcno 2-All records cDefDir = sys(5)+curdir() cTempFile = cDefDir+"t"+right(sys(2015),7) cFlds = "" for ix = 1 to fcount() if !type(field(ix))$"LG" cFlds = cFlds+iif(empty(cFlds),"",",")+field(ix) endif endfor if nScopeOption = 2 cWhere = iif(!empty(set("filter"))," where "+strtran(lower(set("filter")),"hasta.",""), "") select &cFlds from hasta &cWhere into table (cTempFile) else select &cFlds from hasta where recno() = thisform.rcno into table (cTempFile) endif cDataFullPath = dbf(alias()) use in (alias()) select hasta cDSN = "DSN=FoxPro Files;DBQ="+cDefDir+";DefaultDir="+cDefDir+";" cSourceDB = "" cSourceType = "" cOther = "DriverId=536;MaxBufferSize=512;PageTimeout=5;" cSQLStatement = "SELECT * FROM "+cTempFile cDataFile = cTempFile+".dbf" Public oWordDocument oWordDocument = createobject("word.basic") with oWordDocument .FileNewDefault() tcWaitWindowClass = this.findwindowclass("Microsoft Word - Document1") .InsertDatabase(35,511,0, ; cDSN+cSourceDb+cSourceType+cOther, ; cSQLStatement,,,,cDataFile,,,1) .filesaveas(ctempFile,0) && Save as a word doc for mailmerge .fileclose(1) && Close saving * Datasource ready, now create mailmerge main document .filenewdefault() && A template could be here .MailMergeOpenDataSource(cTempFile+".doc") && Set saved file as data source for mailmerge (Directly a table could be set via ODBC) .MailMergeEditMainDocument && Activate the main document .AppShow endwith do while this.findwindowhandle(tcWaitWindowClass)<>0 enddo release oWordDocument erase (cTempFile+".*") ***** * findwindowclass method * Prefer class for Title is likely to change ***** lparameters tcWintitle DECLARE integer FindWindow in WIN32API string cNull, string cWinName declare integer GetClassName in WIN32API integer hWnd, string @cClass, integer nMaxBuffer hWnd = FindWindow(0,tcWintitle) lpClassName = space(200) nBufLen = GetClassName(hWnd,@lpClassName,200) clear dlls return substr(lpClassName,1,nBufLen) ***** * findwindowhandle method * Prefer class for Title is likely to change ***** lparameter tcWinClass DECLARE integer FindWindow in WIN32API string cNull, string cWinName nHWND = FindWindow(tcWinClass,0) clear dlls return nHWNDCetin