none
String is longer than 255 characters (Microsoft Word) RRS feed

  • Question

  • Hi There,

    We are trying to use word library for mail merge functionality in Vb.net project. we are getting below err  when use this API of Microsoft.Office.Interop.Word.MailMerge object. We also try to split SqlStatment in two parts but still getting err. How can we use sql have more than 255 characters? Is there any other way to use mail merge functionality or way of passing data source?

    merge.OpenDataSource(Name:=odcfilename, Connection:=conn, SQLStatement:=sql1, SQLStatement1:=sql2)

    String is longer than 255 characters (Microsoft Word)

    ------------------------------
    Program Location:

       at Microsoft.Office.Interop.Word.MailMerge.OpenDataSource(String Name, Object& Format, Object& ConfirmConversions, Object& ReadOnly, Object& LinkToSource, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Connection, Object& SQLStatement, Object& SQLStatement1, Object& OpenExclusive, Object& SubType)

    • Moved by Youen Zen Monday, May 6, 2013 8:29 AM From Visual Basic
    Friday, May 3, 2013 2:55 AM

Answers

  • It's a limitation of the Word's MailMerge feature. You will either need to shorten the SQL string or use a stored procedure (if the database you are working with supports them). With two SQLStatement arguments the limit is 510 characters when using ODBC to connect.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, May 3, 2013 7:19 PM
  • If your SQL is shorter than the max (510 or whatever it is in the version of Word you are using) you should be able to use the 2 parameters but Word just concatenates the two strings, so using, e.g. "SELECT * FROM" and "mytable" will not work - in that case you would need "SELECT * FROM" and " mytable". Also, word sometimes insists on things that are not strictly necessary in SQL - e.g. It may require you to quote table names even when SQL has no such requirement, or alias table names when SQL has no such requirement.

    Peter Jamieson

    Monday, May 6, 2013 3:25 PM

All replies

  • Hello,

    A better forum is Word for Developers. You can ask this question there by linking back to this question or perhaps a moderator will move this post for you. In either case good luck with this.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Friday, May 3, 2013 3:41 AM
  • It's a limitation of the Word's MailMerge feature. You will either need to shorten the SQL string or use a stored procedure (if the database you are working with supports them). With two SQLStatement arguments the limit is 510 characters when using ODBC to connect.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, May 3, 2013 7:19 PM
  • If your SQL is shorter than the max (510 or whatever it is in the version of Word you are using) you should be able to use the 2 parameters but Word just concatenates the two strings, so using, e.g. "SELECT * FROM" and "mytable" will not work - in that case you would need "SELECT * FROM" and " mytable". Also, word sometimes insists on things that are not strictly necessary in SQL - e.g. It may require you to quote table names even when SQL has no such requirement, or alias table names when SQL has no such requirement.

    Peter Jamieson

    Monday, May 6, 2013 3:25 PM