PDA

View Full Version : Opening a document with VBA



jamtay317
09-25-2014, 11:32 AM
Hello I am new to this site, and thank you for taking the time to read this! I
am working on an Access database, when I Push a button the goal is for for it to
open a document that I have already set up with Mail Merge. When I push the
button it opens the document, but I cannot scroll between the different records.
Im sorry if I should have posted this in the word forum.


Here is the code that I've already created.


Code:
Private Sub cbFESOP_Click()
Dim wrd As Word.Application
Set wrd = CreateObject("Word.Application")
Dim doc As Word.Document
Set doc = wrd.Documents.Open("Y:\Reports\FESOP Certification.docx")

wrd.Visible = True
End Sub

any and all help will be appreciated thank you

ranman256
09-25-2014, 01:02 PM
I always reconnect to the db.


with wrd
.ActiveDocument.MailMerge.OpenDataSource Name:= _
"\\myfolder\db1.mdb (file://\\myfolder\db1.mdb)", ConfirmConversions:= _
False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="QUERY qsMyQuery", SQLStatement:="SELECT * FROM [qsCheers]", _
SQLStatement1:="", SubType:=wdMergeSubTypeOther

With .ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End Sub