Visual Foxpro
- How to Create Mail Merge in Visual Foxpro 6.0 Where using Office 2007
Answers
How to Create Mail Merge in Visual Foxpro 6.0 Where using Office 2007
*!* Author: Cetin Basoz *!* MailMerge sample that works with newer versions too Wait Window Nowait "Creating Word Document.Please wait..." #Define wdOpenFormatAuto 0 #Define wdSendToNewDocument 0 #Define wdSendToPrinter 1 #Define wdSendToEmail 2 #Define wdSendToFax 3 lcConnection = "Provider=VFPOLEDB;Data source="+_samples+'data\testdata.dbc' Strtofile('','myDummy.udl') m.lcSource = Fullpath('myDummy.udl') lcSQLStatement = "select e.First_Name,e.Last_Name,e.Notes from [Employee] e" *** set the LOCALEID to English nlLocaleId=Sys(3004) && Save local id =Sys(3006,1033) && We will be sending instructions in English *** set the LOCALEID to English oWordDocument=Createobject("word.application") && Create word object With oWordDocument .documents.Add With .ActiveDocument.Mailmerge .OpenDataSource(m.lcSource, wdOpenFormatAuto,.F.,,.T.,,,,,,,m.lcConnection, m.lcSQLStatement) .EditMainDocument && Activate the main document *!* Add some merge fields and typ text programmatically .Fields.Add(.Application.Selection.Range, "Last_Name") .Application.Selection.TypeText(", ") .Fields.Add(.Application.Selection.Range, "First_Name") With .Application.Selection.Font .Italic = .F. .Name = 'Arial' .Size = 10 Endwith .Application.Selection.TypeText(Chr(13)+"Here is your notes data :"+Chr(13)+Chr(13)) With .Application.Selection.Font .Bold = .T. .Color = Rgb(0,0,255) Endwith .Fields.Add(.Application.Selection.Range, "Notes") With .Application.Selection.Font .Bold = .F. .Color = Rgb(0,0,0) ENDWITH * .Destination = wdSendToNewDocument * .Execute() Endwith .Visible = .T. && Show word app .Activate Endwith **** Set the LocaleId to the previous value =Sys(3006,Val(nlLocaleId))- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorMonday, November 09, 2009 8:50 AM
All Replies
- I would start with doing a web search for the words "FoxPro Word MailMerge".
Craig Berntson MCSD, Visual FoxPro MVP www.craigberntson.com - check Below link. it may be helpful youhttp://www.tek-tips.com/viewthread.cfm?qid=1500523&page=3http://www.tek-tips.com/faqs.cfm?fid=2410http://www.tek-tips.com/viewthread.cfm?qid=1500523&page=3
Please "Mark as Answer" if this post answered your question. :)
Kalpesh Chhatrala | Software Developer | Rajkot | India
Kalpesh's Blog How to Create Mail Merge in Visual Foxpro 6.0 Where using Office 2007
*!* Author: Cetin Basoz *!* MailMerge sample that works with newer versions too Wait Window Nowait "Creating Word Document.Please wait..." #Define wdOpenFormatAuto 0 #Define wdSendToNewDocument 0 #Define wdSendToPrinter 1 #Define wdSendToEmail 2 #Define wdSendToFax 3 lcConnection = "Provider=VFPOLEDB;Data source="+_samples+'data\testdata.dbc' Strtofile('','myDummy.udl') m.lcSource = Fullpath('myDummy.udl') lcSQLStatement = "select e.First_Name,e.Last_Name,e.Notes from [Employee] e" *** set the LOCALEID to English nlLocaleId=Sys(3004) && Save local id =Sys(3006,1033) && We will be sending instructions in English *** set the LOCALEID to English oWordDocument=Createobject("word.application") && Create word object With oWordDocument .documents.Add With .ActiveDocument.Mailmerge .OpenDataSource(m.lcSource, wdOpenFormatAuto,.F.,,.T.,,,,,,,m.lcConnection, m.lcSQLStatement) .EditMainDocument && Activate the main document *!* Add some merge fields and typ text programmatically .Fields.Add(.Application.Selection.Range, "Last_Name") .Application.Selection.TypeText(", ") .Fields.Add(.Application.Selection.Range, "First_Name") With .Application.Selection.Font .Italic = .F. .Name = 'Arial' .Size = 10 Endwith .Application.Selection.TypeText(Chr(13)+"Here is your notes data :"+Chr(13)+Chr(13)) With .Application.Selection.Font .Bold = .T. .Color = Rgb(0,0,255) Endwith .Fields.Add(.Application.Selection.Range, "Notes") With .Application.Selection.Font .Bold = .F. .Color = Rgb(0,0,0) ENDWITH * .Destination = wdSendToNewDocument * .Execute() Endwith .Visible = .T. && Show word app .Activate Endwith **** Set the LocaleId to the previous value =Sys(3006,Val(nlLocaleId))- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorMonday, November 09, 2009 8:50 AM


