Re: mail merge code template with connection strings



If you manually attach the data source, you could then use the following
code to get the details of the connection

'Get the details of the datasource

With ActiveDocument.MailMerge.DataSource

MsgBox .Name

MsgBox .QueryString

End With


There's a few other things that you need to supply to execute the merge to
email - the MailAddressFieldName as a minimum.

With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.MailAddressFieldName = "emailfield"
.MailAsAttachment = True 'or False
.MailFormat = wdMailFormatHTML 'or wdMailFormatPlainText
.MailSubject = "some string"
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute pause:=False
End With

Plus, you may have to deal with Outlook Security issues for which you can
check out ExpressClickYes (via Google)
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Diane" <Diane@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AAB31E5B-3CC4-4470-B8D7-62F2324F44A8@xxxxxxxxxxxxxxxx
Group,
I am wanting to create a macro that will connect to a file in code and
perform a mail merge to outlook, the file I connect to will always be the
same file.

I am currently connecting with an ODBC connection, I want to change
this....I don't want to be running around installing this on many pc's.
If I
can create an ado connection in code, I can eliminate this problem.
Also,
my current macro displays the mail merge dialogue box, I don't want that
either, my goal is to connect to my file, complete a mail merge, all
within
code, without user intervention.

I can connect to my database, but I can't seem to get the document to
merge
with it??

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strsql As String


Set rst = New ADODB.Recordset
Const cnnstring = "Provider=IBMDA400; Data Source=iSeries"

strsql = "select * from mylib.myfile"

--->(this doesn't work for me)--->ActiveDocument.mailmerge.OpenDataSource
name:=cnnstring


--->this is step #2 that I want to work----->
With ActiveDocument.mailmerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute pause:=False
End With


rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing

Any examples of creating this in code would be appreciated!!



.



Relevant Pages

  • Re: mail merge code template with connection strings
    ... Doug & Peter, ... .FirstRecord = wdDefaultFirstRecord ... I am currently connecting with an ODBC connection, ... Set rst = New ADODB.Recordset ...
    (microsoft.public.word.mailmerge.fields)
  • Re: DriverManager vs. DataSource?
    ... > class to establish the connection. ... it is possible to use the DriverManager interface. ... JDBC driver jars go in a 'common' directory in the container. ... > the DataSource interface will typically be registered with a JNDI ...
    (comp.lang.java.databases)
  • Re: Connection for Data Source in SSAS 2005 Tutorial Lesson 6
    ... double click on the datasource and then click on ... I noticed that my server explorer showed a connection to ... When connecting to SQL Server 2005, this failure may be caused by the ... not be made to the data source with the DataSourceID of 'Adventure ...
    (microsoft.public.sqlserver.olap)
  • Re: ConnectionPoolDataSource + MM MySQL + Tomcat4
    ... to work with Tomcat 5.0.28 and MySQL or Oracle. ... <ResourceParams> ... in functions needing DB access, use the DataSource variable ... to create a Connection ...
    (comp.lang.java.programmer)
  • Re: Read from one, write into another data source
    ... this sounds like you're using ADO to to transport (bulk copy) data. ... > contents into another DataSource. ... > OleDbConnection connection = adapter.SelectCommand.Connection; ...
    (microsoft.public.data.ado)

Loading