View Single Post
  #10   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default how to retrieve mailmerge field name using vb.net

1)

yes, that's why I said at the beginning of this thread that it's not easy to
get this right. In other words, you have to solve /all/ the problems. In my
opinion, a good designer/programmer should either be able to solve each
probem they come across and avoid taking routes where they get stuck.

If I went down that route I would consider something like
a. saving a copy of the mailmerge main document
b. creating an output document
c. for each record in the data source
- retrieve the copy
- make sure my view of the document is set up so I can process its
fields (e.g., if you want to look for MERGFIELD fields by looking for
chevrons , you can't be in preview view, where you see result data, or
"field code" view, where you see { MERGEFIELD "mergefield name" }
- evaluate the fields
- copy everything except possibly the final paragraph mark and append
it to the output document
d. close everything

2)in method 2,How to replace DSN info wth slq server connection string
like "Data Source=servername;initial catalog=dbname;Integrated
security=true;"
or the provider name. I am using sql server 2000


When it connects to an ODBC data source, Word OpenDataSource always
references an ODBC DSN of some kind. You can't use a DSN-less connection,
e.g. specifying Driver={whatever}, as you can in some other applications.

However, anything in the existing DSN can be overridden by an item in the
COnnection string, /except/ the driver name. So if you know you have a DSN
called Connect_To_DB that uses the SQl Server driver, and specify

Connection:="DSN=Connect_To_DB;Data Source=servername;initial
catalog=dbname;Integrated security=True;"

it should work. Or you can use a file dsn. But you have to have /a/ DSN.
It's an irritating limitation of Word. The same situation is true if you
want to use an OLEDB connection: for SQL Server you have to have either a
..udl file or a .odc file. You can't just specify an OLEDB connection string
(even though you have to specify the provider anyway).

3)if I give the user an option to create a new template;
a)how to restrict the merge field values:what i mean is user only able to
see the mergefields that i created(in the dropdown box)


If there is a header Source, the user should be able to select from the list
of coumns in the Header Source (header Sources are not supported in the User
Interface in Word 2002 and later, and you may find they do not work the way
they were originally supposed to). If you are going to use a header Source,
I'd make it a Word document.

If you don't have a header source, the user will see the list of columns
returned by the SELECT used to create the data source. if there is no data
source, they see no list of columns. If you do not want to connect to the
real data source, you could connect to another data source with identical
column names (it is the field names that Word uses that really count)
temporarily, then open the real data source when you need it.

Peter Jamieson
"srid" wrote in message
...
Questions:
1)in method 1 ,i am saving each merged record as a file
a)How to show all the merged records in one document with new pages or
read
the saved files and put them in one word document. Each file info should
be
in a new page?
2)in method 2,How to replace DSN info wth slq server connection string
like "Data Source=servername;initial catalog=dbname;Integrated
security=true;"
or the provider name. I am using sql server 2000
3)if I give the user an option to create a new template;
a)how to restrict the merge field values:what i mean is user only able to
see the mergefields that i created(in the dropdown box)

thanks in advance