maatwerk
asked on
Invalid typecase error while parsing autotext.
I am trying to create a mailmerge procedure in Delphi 6. But i always get an invalid typecase error, when i try to pas "autotext" as an parameter. If i leave this parameter empty no error occurs. But i need this parameter in order to parse the mergefields...
Please Help!
procedure TForm1.Button1Click(Sender : TObject);
var
oLabel,oAutotext,oAdres,oE tiket,oTim eout,opaus e:OleVaria nt;
begin
oEtiket:='xxxx';
olabel:='8389';
oAdres:='Address:=';
oTimeout:=30;
with oApp.Documents.Add(EmptyPa ram,EmptyP aram,Empty Param,Empt yParam).Ma ilMerge.Fi elds do Begin
Add(Application.Selection. Range,'Con tact_Name' );
Application.Selection.Type Paragraph;
Add(Application.Selection. Range,'oAd dress');
Application.Selection.Type Paragraph;
Add(Application.Selection. Range,'Cit y');
Application.Selection.Type Text('');
Add(Application.Selection. Range,'Pos tal_Code') ;
Application.Selection.Type Text('---' );
Add(Application.Selection. Range,'Cou ntry');
end;
oAutotext:=oApp.NormalTemp late.AutoT extEntries .Add('MyLa belLayout' ,oApp.Acti veDocument .Content);
ShowMessage(oAutotext);
oApp.ActiveDocument.Conten t.Delete(E mptyParam, EmptyParam );
oDoc.MailMerge.MainDocumen tType := wdMailingLabels;
oDoc.MailMerge.OpenDataSou rce('C:\da ta.txt',Em ptyParam,E mptyParam, EmptyParam ,EmptyPara m,EmptyPar am,EmptyPa ram,
EmptyParam,EmptyParam,Empt yParam,Emp tyParam,Em ptyParam,E mptyParam, EmptyParam );
oApp.MailingLabel.CreateNe wDocument
// ERROR HAPPENS OVERHERE TYPECAST ERROR!
(oLabel,EmptyParam,oAutote xt,EmptyPa ram,EmptyP aram);
//Execute the mail merge to generate the labels.
oDoc.MailMerge.Destination :=wdSendTo NewDocumen t;
opause:=True;
oDoc.MailMerge.Execute(opa use);
oAutotext.Delete;
oDoc.Close;
oApp.Visible;
oApp.NormalTemplate.Saved: =True;
end;
Please Help!
procedure TForm1.Button1Click(Sender
var
oLabel,oAutotext,oAdres,oE
begin
oEtiket:='xxxx';
olabel:='8389';
oAdres:='Address:=';
oTimeout:=30;
with oApp.Documents.Add(EmptyPa
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
end;
oAutotext:=oApp.NormalTemp
ShowMessage(oAutotext);
oApp.ActiveDocument.Conten
oDoc.MailMerge.MainDocumen
oDoc.MailMerge.OpenDataSou
EmptyParam,EmptyParam,Empt
oApp.MailingLabel.CreateNe
// ERROR HAPPENS OVERHERE TYPECAST ERROR!
(oLabel,EmptyParam,oAutote
//Execute the mail merge to generate the labels.
oDoc.MailMerge.Destination
opause:=True;
oDoc.MailMerge.Execute(opa
oAutotext.Delete;
oDoc.Close;
oApp.Visible;
oApp.NormalTemplate.Saved:
end;
listening
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
listening
ASKER
I finally got it working. I translated this from VB sourcecode see:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q258512
The error got caused by the fact that i indeed passed a object as a parameter. So thanks. I have noticed that this subject also interest others so here the sourcecode it work on my machine... Iam using delphi 6 and Office 2000.
procedure TForm1.Button1Click(Sender : TObject);
var
oLabel,oAutotext,oAdres,oE tiket,oTim eout,oFals e,oAutoTxt :OleVarian t;
begin
oEtiket:='xxxx';
olabel:='8389';
oAdres:='Address';
oTimeout:=30;
// odoc is tworddocument oApp is twordapplication Office 2000
with odoc.MailMerge.Fields do Begin
Add(Application.Selection. Range,'Con tact_Name' );
Application.Selection.Type Paragraph;
Add(Application.Selection. Range,'Add ress');
Application.Selection.Type Paragraph;
Add(Application.Selection. Range,'Cit y');
Application.Selection.Type Text('');
Add(Application.Selection. Range,'Pos tal_Code') ;
Application.Selection.Type Text('---' );
Add(Application.Selection. Range,'Cou ntry');
end;
oAutotext :='MyLabelLayout';
oAutoTxt:=oApp.NormalTempl ate.AutoTe xtEntries. Add(oAutot ext,oDoc.C ontent);
odoc.Content.Delete(EmptyP aram,Empty Param);
//Merge fields in document no longer needed now
//that the AutoText entry for the label layout
//has been added so delete it.
odoc.MailMerge.MainDocumen tType := wdMailingLabels;
//Set up the mail merge type as mailing labels and use
//a tab-delimited text file as the data source.
//Create the new document for the labels using the AutoText entry
//you added -- 5160 is the label number to use for this sample.
//You can specify the label number you want to use for the output
//in the Name argument.
odoc.MailMerge.OpenDataSou rce('C:\da ta1.txt',E mptyParam, EmptyParam ,EmptyPara m,EmptyPar am,EmptyPa ram,EmptyP aram,
EmptyParam,EmptyParam,Empt yParam,Emp tyParam,Em ptyParam,E mptyParam, EmptyParam );
oApp.MailingLabel.CreateNe wDocument( oLabel,oAd res,oAutot ext,EmptyP aram,Empty Param);
//Execute the mail merge to generate the labels.
odoc.MailMerge.Destination :=wdSendTo NewDocumen t;
oFalse:=False;
//Execute the mail merge to generate the labels.
oDoc.MailMerge.Execute(Emp tyParam);
oAutoTxt.Delete;
//Close the original document and make Word visible so that
//the mail merge results are displayed
odoc.Close(oFalse);
oApp.Visible:=True;
//Prevent save to Normal template when user exits Word
oApp.NormalTemplate.Saved: =True;
end;
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q258512
The error got caused by the fact that i indeed passed a object as a parameter. So thanks. I have noticed that this subject also interest others so here the sourcecode it work on my machine... Iam using delphi 6 and Office 2000.
procedure TForm1.Button1Click(Sender
var
oLabel,oAutotext,oAdres,oE
begin
oEtiket:='xxxx';
olabel:='8389';
oAdres:='Address';
oTimeout:=30;
// odoc is tworddocument oApp is twordapplication Office 2000
with odoc.MailMerge.Fields do Begin
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
end;
oAutotext :='MyLabelLayout';
oAutoTxt:=oApp.NormalTempl
odoc.Content.Delete(EmptyP
//Merge fields in document no longer needed now
//that the AutoText entry for the label layout
//has been added so delete it.
odoc.MailMerge.MainDocumen
//Set up the mail merge type as mailing labels and use
//a tab-delimited text file as the data source.
//Create the new document for the labels using the AutoText entry
//you added -- 5160 is the label number to use for this sample.
//You can specify the label number you want to use for the output
//in the Name argument.
odoc.MailMerge.OpenDataSou
EmptyParam,EmptyParam,Empt
oApp.MailingLabel.CreateNe
//Execute the mail merge to generate the labels.
odoc.MailMerge.Destination
oFalse:=False;
//Execute the mail merge to generate the labels.
oDoc.MailMerge.Execute(Emp
oAutoTxt.Delete;
//Close the original document and make Word visible so that
//the mail merge results are displayed
odoc.Close(oFalse);
oApp.Visible:=True;
//Prevent save to Normal template when user exits Word
oApp.NormalTemplate.Saved:
end;
ASKER
I finally got it working. I translated this from VB sourcecode see:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q258512
The error got caused by the fact that i indeed passed a object as a parameter. So thanks. I have noticed that this subject also interest others so here the sourcecode it work on my machine... Iam using delphi 6 and Office 2000.
procedure TForm1.Button1Click(Sender : TObject);
var
oLabel,oAutotext,oAdres,oE tiket,oTim eout,oFals e,oAutoTxt :OleVarian t;
begin
oEtiket:='xxxx';
olabel:='8389';
oAdres:='Address';
oTimeout:=30;
// odoc is tworddocument oApp is twordapplication Office 2000
with odoc.MailMerge.Fields do Begin
Add(Application.Selection. Range,'Con tact_Name' );
Application.Selection.Type Paragraph;
Add(Application.Selection. Range,'Add ress');
Application.Selection.Type Paragraph;
Add(Application.Selection. Range,'Cit y');
Application.Selection.Type Text('');
Add(Application.Selection. Range,'Pos tal_Code') ;
Application.Selection.Type Text('---' );
Add(Application.Selection. Range,'Cou ntry');
end;
oAutotext :='MyLabelLayout';
oAutoTxt:=oApp.NormalTempl ate.AutoTe xtEntries. Add(oAutot ext,oDoc.C ontent);
odoc.Content.Delete(EmptyP aram,Empty Param);
//Merge fields in document no longer needed now
//that the AutoText entry for the label layout
//has been added so delete it.
odoc.MailMerge.MainDocumen tType := wdMailingLabels;
//Set up the mail merge type as mailing labels and use
//a tab-delimited text file as the data source.
//Create the new document for the labels using the AutoText entry
//you added -- 5160 is the label number to use for this sample.
//You can specify the label number you want to use for the output
//in the Name argument.
odoc.MailMerge.OpenDataSou rce('C:\da ta1.txt',E mptyParam, EmptyParam ,EmptyPara m,EmptyPar am,EmptyPa ram,EmptyP aram,
EmptyParam,EmptyParam,Empt yParam,Emp tyParam,Em ptyParam,E mptyParam, EmptyParam );
oApp.MailingLabel.CreateNe wDocument( oLabel,oAd res,oAutot ext,EmptyP aram,Empty Param);
//Execute the mail merge to generate the labels.
odoc.MailMerge.Destination :=wdSendTo NewDocumen t;
oFalse:=False;
//Execute the mail merge to generate the labels.
oDoc.MailMerge.Execute(Emp tyParam);
oAutoTxt.Delete;
//Close the original document and make Word visible so that
//the mail merge results are displayed
odoc.Close(oFalse);
oApp.Visible:=True;
//Prevent save to Normal template when user exits Word
oApp.NormalTemplate.Saved: =True;
end;
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q258512
The error got caused by the fact that i indeed passed a object as a parameter. So thanks. I have noticed that this subject also interest others so here the sourcecode it work on my machine... Iam using delphi 6 and Office 2000.
procedure TForm1.Button1Click(Sender
var
oLabel,oAutotext,oAdres,oE
begin
oEtiket:='xxxx';
olabel:='8389';
oAdres:='Address';
oTimeout:=30;
// odoc is tworddocument oApp is twordapplication Office 2000
with odoc.MailMerge.Fields do Begin
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
Application.Selection.Type
Add(Application.Selection.
end;
oAutotext :='MyLabelLayout';
oAutoTxt:=oApp.NormalTempl
odoc.Content.Delete(EmptyP
//Merge fields in document no longer needed now
//that the AutoText entry for the label layout
//has been added so delete it.
odoc.MailMerge.MainDocumen
//Set up the mail merge type as mailing labels and use
//a tab-delimited text file as the data source.
//Create the new document for the labels using the AutoText entry
//you added -- 5160 is the label number to use for this sample.
//You can specify the label number you want to use for the output
//in the Name argument.
odoc.MailMerge.OpenDataSou
EmptyParam,EmptyParam,Empt
oApp.MailingLabel.CreateNe
//Execute the mail merge to generate the labels.
odoc.MailMerge.Destination
oFalse:=False;
//Execute the mail merge to generate the labels.
oDoc.MailMerge.Execute(Emp
oAutoTxt.Delete;
//Close the original document and make Word visible so that
//the mail merge results are displayed
odoc.Close(oFalse);
oApp.Visible:=True;
//Prevent save to Normal template when user exits Word
oApp.NormalTemplate.Saved:
end;