Thank you everyone for responding. I was using code from a HENTZENWERKE book (Microsoft office automation with visual foxpro) and it wasn't working out too good. I sat down and came up with the following code which is working out for me alot better. I am going to look for the bookmark possibility.
Thanks again everyone!
**************************************************************************
* CreateDataSource.PRG
LPARAMETERS oDoc, cCursor ,bToPrn ,cCaption &&, cDocument
#INCLUDE 'INCLUDE\APPINCL.H'
LOCAL cCSV, ; && CSV File for datasource
cIndex, ; && index of searched document
cFrmLet && Form letter
IF VARTYPE(bToPrn)="U"
bToPrn = .F.
ENDIF
cCSV = sys(2023) + "\" +"T"+ SUBSTR(SYS(2015),2)+".txt"
****************
*Create CSV file
****************
SELECT 0
SET EXCLUSIVE OFF
USE (cCursor) AGAIN IN 0 ALIAS MergeCursor
SELECT MergeCursor
*browse
COPY TO (cCSV) TYPE CSV
USE IN MergeCursor
***Get ref ot word object
TRY
oWDoc = GETOBJECT(oDoc)
**Find MM template
cIndex=GetItmInd(JUSTFNAME(oDoc))
IF cIndex = 0
cIndex = 1
endif
owdoc.Application.Documents.Item(cIndex).Activate
owdoc.Application.Documents.Item(cIndex).MailMerge.OpenDataSource(cCSV)
IF !bToPrn
owdoc.Application.Documents.Item(cIndex).MailMerge.Destination= 0 && wdSendToNewDocument
Else
With owdoc.Application.Documents.Item(cIndex).application.Dialogs(97)
.Printer = DOCPRINTER
.DoNotSetAsSysDefault = .T.
.Execute
EndWith
owdoc.Application.Documents.Item(cIndex).MailMerge.Destination= 1 && 0 sends to document 1 sends to printer
ENDIF
*/Added 2/11/04 for printing purposes will set Document (just document to printer name of choice) LA
owdoc.Application.Documents.Item(cIndex).MailMerge.Execute
IF !bToPrn
owdoc.Application.Documents.Item(1).activate()
With owdoc.Application.Documents.Item(1).application.Dialogs(97)
.Printer = DOCPRINTER
.DoNotSetAsSysDefault = .T.
.Execute
EndWith
owdoc.Application.Documents.Item(1).Windows.Item(1).Caption = cCaption
owdoc.Application.Documents.Item(1).Windows.Item(1).Visible = .T.
ENDIF
CATCH TO oERR
MESSAGEBOX("error "+oERR.message+CHR(13)+"In procedure ";
+oERR.procedure+CHR(13)+"Line #";
+STR(oERR.lineno),16,"Error")
RELEASE owdoc
ENDTRY
**Find MM template
cIndex=GetItmInd(JUSTFNAME(oDoc))
IF cIndex=0
cIndex=2
endif
owdoc.Application.Documents.Item(cIndex).Close
ERASE (cCSV)
RELEASE owdoc,cCSV,cIndex,cFrmLet,bToPrn
********************************************************************************
FUNCTION GetItmInd()
*This function recieves as a parameter the path to a file
*then scans open word documents till it finds the correct index for ref
*then returns the index #
********************************************************************************
LPARAMETERS cFname
LOCAL nDocs, ; && # of Open documents
nTempInd && index of Template
nDocs = owdoc.Application.Documents.count
nTempInd = 0
DIMENSION cDocnames(nDocs) && array of document names
FOR x=1 TO nDocs && popolate array with open word documents
cDocnames(x)= owdoc.Application.Documents.Item(x).name
IF cDocnames(x) = cFname
nTempInd = x && determining template index
ENDIF
ENDFOR
RETURN nTempInd
ENDFUNC
********************************************************************