Vbasic merge From Access to Word

  • Thread starter Thread starter ruaduck
  • Start date Start date
R

ruaduck

I am trying to merge my data to Microsoft word using a button in access on my
form. The button says Create Letter and so when it is clicked it needs to
merge the database items for the specific record to a letter i have made in
word. Any help would be nice.
 
Forgot to add in my source code i have been trying to use.


Private Sub Command88_Click()
On Error GoTo Err_Command88_Click
If IsNull([LName]) Then
MsgBox "Please Enter in Last Name"
Exit Sub

Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim objWord As Word.Document
Dim strSQL As String
Dim oConn As ADODB.Connection
Set objWord =
GetObject("\\Amedfsgpcbut800\Shared\4-Admin\ADForm.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the database.
objWord.MailMerge.OpenDataSource _
Name:=CurrentDb.Name, _
LinkToSource:=True, _
Connection:="VIEW AD", _
SQLStatement:="Select * from [AD] WHERE(([MERGED])<>'MEMO_DONE')"
objWord.MailMerge.Execute
objWord.Application.ActiveDocument.SaveAs
objWord.Application.ActiveDocument.SaveAs("\\amedfsgpcbut800\shared\4-Admin\Additional_Duty_memos\to_be_signed" & [FName] & " " & Format([LName], [Duty]))
objWord.Close wdDoNotSaveChanges

Dim Workbase As Database
Set Workbase = CurrentDb
strSQL = "UPDATE [AD] Set MERGED='Merged'
WHERE(([MERGED])<>'MEMO_DONE'"
Workbase.Execute (strSQL)
DoCmd.Close


End If
Exit_Command88_Click:
Exit Sub

Err_Command88_Click:
If Err = 2501 Then 'The RunCommand action was canceled
Exit Sub
Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Command88_Click
End If

End Sub
 
ruaduck said:
I am trying to merge my data to Microsoft word using a button in access on
my
form. The button says Create Letter and so when it is clicked it needs to
merge the database items for the specific record to a letter i have made
in
word. Any help would be nice.

I have a nice working sample that does a merge of the current record to
word.

The sample I have can be found here:
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html

What is nice/interesting about my sample is that is specially designed to
enable ANY form with ONE LINE of code....

Thus, each time you build a new form, you can word merge enable it with
great ease.

Make sure you read the instructions from above, and you should eventually
get to the follwoing page
http://www.members.shaw.ca/AlbertKallal/wordmerge/page2.html


Note that the merge can also use a query, and thus you dont have to merge
just "one" record..

After the merge occurs, you get a plain document WITHOUT any merge fields,
and this allows the end user to save, edit, or even email the document
(since the merge fields are gone after the merge occurs).

Give the above a try.
 
Back
Top