D
Dadio
Hello
On my Access database form I have a command button which opens a Word mail
merge document in which I have created a number of fields (Title, FirstName,
LastName, Address1 etc.)
I would like to be able to populate the Word document with the contents of
the currently selected Access record so that when I press the button in
Access, Word opens with the appropriate fields populated and ready to print.
It is a "one off" event which I will use, typically, to print a single
letter or invoice which is more easily edited in Word.
My code at the moment is:
-------
Private Sub StartWord_Click()
On Error GoTo Err_StartWord_Click
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "m:\database\poolshop\Invoice new.doc"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open FileName:=LWordDoc
End If
Exit_StartWord_Click:
Exit Sub
Err_StartWord_Click:
MsgBox Err.Description
Resume Exit_StartWord_Click
End Sub
-------
But at the moment it does not automatically populate Word with anything, or
at least, by default, I see the contents of the first record. What I want is
to see, in my Word fields, the data from the current record. I can use the
normal mail merge search facility in Word to do a query and find the right
record but that is clumsy and I know you can do better.
I do not want to sound arrogant (be kind to me) but I do quite like the bit
of code that I have used (copied from elsewhere) and rather hope that all I
need to do is add a "current.record" type of command to it somewhere to get
the result that I need.
Thank you for your help, keep it simple.
Les
On my Access database form I have a command button which opens a Word mail
merge document in which I have created a number of fields (Title, FirstName,
LastName, Address1 etc.)
I would like to be able to populate the Word document with the contents of
the currently selected Access record so that when I press the button in
Access, Word opens with the appropriate fields populated and ready to print.
It is a "one off" event which I will use, typically, to print a single
letter or invoice which is more easily edited in Word.
My code at the moment is:
-------
Private Sub StartWord_Click()
On Error GoTo Err_StartWord_Click
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "m:\database\poolshop\Invoice new.doc"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open FileName:=LWordDoc
End If
Exit_StartWord_Click:
Exit Sub
Err_StartWord_Click:
MsgBox Err.Description
Resume Exit_StartWord_Click
End Sub
-------
But at the moment it does not automatically populate Word with anything, or
at least, by default, I see the contents of the first record. What I want is
to see, in my Word fields, the data from the current record. I can use the
normal mail merge search facility in Word to do a query and find the right
record but that is clumsy and I know you can do better.
I do not want to sound arrogant (be kind to me) but I do quite like the bit
of code that I have used (copied from elsewhere) and rather hope that all I
need to do is add a "current.record" type of command to it somewhere to get
the result that I need.
Thank you for your help, keep it simple.
Les