File DSN in vba

H

Harry

Hello All,

So fa so good, I managed to "mailmerge" the content of a query to a
predefined word template. It creates a new document (in final view) and I am
able to toggle between the records.
However the template is using a fileDSN and everytime I have to manually
click the right fileDSN before the new document is opened and ready for use.

My challenge now is how to script (VBA) so that this manual action is no
longer required.
please find below my script.

'//begin code
Private Sub MS_Word_Click()

Dim WordApp As Object
Dim WordDoc As Word.Document
Dim strLetter As String
Dim strConnect As String

Location = "C:\Documents and Settings\Harry\Application
Data\Microsoft\Templates\"
FileName = "Brief-FloorCraft-Sjabloon.dot"

Set WordApp = CreateObject("Word.Application")

Set WordDoc = WordApp.Documents.Add(Location & FileName)

Set objView = WordApp.ActiveDocument.ActiveWindow.View
objView.ShowRevisionsAndComments = False
objView.RevisionsView = wdRevisionsViewFinal


WordDoc.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\Harry\My Documents\My Data
Sources\FloorCraftEvents Q-RelatiePostAdres.odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=MSDASQL.1;Persist Security Info=False;Extended
Properties=""DSN=MS Access Database;DBQ=D:\FLOORCRAFT
EVENTS\FloorCraftEvents.mdb;DefaultDir=D:\FLOORCRAFT
EVENTS;DriverId=25;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;"";Initial Catalog" _
, SQLStatement:="SELECT * FROM `Q-RelatiePostAdres`",
SQLStatement1:="", _
SubType:=wdMergeSubTypeOther
WordDoc.MailMerge.ViewMailMergeFieldCodes = wdToggle


WordApp.Visible = True

End Sub

'//end code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top