girls3dog1
Programmer
Pb8
I have a problem with the following code that converts dw to an MS Word
file. I get an error message that states the following: "Error
calling external object function execute at line 74." Line 74 is the
mailmerge.execute, which is shown below. This is my first attempt at
ole and maybe I have the testdocument.doc set up incorrectly. I believe the error is generated by the fact that when my word template file "c:\database\testdocument2.dot" opens it does not have the datasource file attached for some reason. Thanks
in advance for any help provided.
///////////////////////////////////
////// Datawindow data to Word ////
///////////////////////////////////
pointer oldpointer // Declares a pointer variable
oldpointer = SetPointer(HourGlass!)
//Define ole object and Connect to Word
OleObject ole_Word
integer li_connect_result, ll_field_count
string ls_word_data, ls_document_name, ls_letter_data
string ls_insttag, ls_moduletag, ls_signaltag
ole_Word = Create OleObject
li_connect_result = ole_Word.ConnectToNewObject('word.application.10')
If li_connect_result <> 0 Then
Destroy ole_Word
Messagebox("Ole Error","Unable to connect Microsoft Word.")
Return
End if
//Get data from datawindow and place it in Word datasource file
c:\database\test1.doc
Datawindowchild dw_child
dw_io_list.GetChild('dw_1',dw_child)
ls_insttag = dw_child.getitemstring(1,'tbl_instrument_list_insttag')
ls_moduletag = dw_child.getitemstring(1,'tbl_io_list_controlmodule')
ls_signaltag = dw_child.getitemstring(1,'tbl_io_list_signaltag')
ls_letter_data = "Inst_tag,Module_tag,Signal_tag" + " ~t" + trim
(ls_insttag) + ", " + trim(ls_moduletag) + ", " + trim(ls_signaltag)
For ll_field_count = 2 to dw_child.rowcount( )
ls_insttag = dw_child.getitemstring
(ll_field_count,'tbl_instrument_list_insttag')
ls_moduletag = dw_child.getitemstring
(ll_field_count,'tbl_io_list_controlmodule')
ls_signaltag = dw_child.getitemstring
(ll_field_count,'tbl_io_list_signaltag')
ls_letter_data = ls_letter_data + "~t" + trim(ls_insttag) + ", " +
trim(ls_moduletag) + ", " + trim(ls_signaltag)
Next
ls_letter_data = ls_letter_data + "~t"+ "~r"
ole_Word.Application.Visible = True
ls_document_name = "c:\database\test1.doc"
ole_Word.Documents.Open(ls_document_name)
ole_Word.Application.Selection.WholeStory
ole_Word.Selection.TypeText(ls_letter_data)
ole_Word.Application.Selection.Delete(1,1)
ole_Word.ActiveDocument.SaveAs(ls_document_name)
ole_Word.ActiveDocument.Close(0)
//Open document and merge new data and save
ls_document_name = "c:\database\testdocument2.dot"
ole_Word.Documents.Open(ls_document_name)
ole_Word.ActiveDocument.MailMerge
ole_Word.ActiveDocument.MailMerge.Destination = 1
(Line 74) ole_Word.ActiveDocument.MailMerge.Execute(False) (Line 74)
ole_Word.DisconnectObject()
Destroy ole_Word
SetPointer(oldpointer)