VBA

Moderators: PavlinII
Number of threads: 1673
Number of posts: 3078

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
VBA - Mail Merge Access to Word Template Posted by Jademonkey2k on 20 Jan 2005 at 9:55 AM
This message was edited by Jademonkey2k at 2005-1-20 9:56:53

Hiya peeps,

jus waqndering if anyone can help, iv made a form in Access and i am able to navigate records via it, easy right lol? well im trying to make a button that when clicked takes the current record and merges it with a ready made mail merge Word document, iv managed to comple this and make it work to a certain extent its just it doesnt merge the one record, it merges them all? i only want it to merge the current record, i dont know if anyone can help me with this? i'll put the code im using in a VBA module below, if anyone can tell me what im doing wrong or has a solution i would be greatful.




Function MergeIt()
Dim ObjWord As Word.Document
Set ObjWord = GetObject("C:\Documents and Settings\Administrator\Desktop\Database Project\Master Thank You Letter.doc", "Word.Document")
ObjWord.Application.Visible = True
ObjWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\Administrator\Desktop\Database Project\Database 1.mdb", _
LinkToSource:=True, Connection:="TABLE Main_Contracts_Database", _
SQLStatement:="SELECT * FROM [Main_Contracts_Database]"
ObjWord.MailMerge.Execute
End Function


Report
Re: VBA - Mail Merge Access to Word Template Posted by jleg on 26 Jan 2005 at 2:35 PM
: This message was edited by Jademonkey2k at 2005-1-20 9:56:53

: Hiya peeps,
:
: jus waqndering if anyone can help, iv made a form in Access and i am able to navigate records via it, easy right lol? well im trying to make a button that when clicked takes the current record and merges it with a ready made mail merge Word document, iv managed to comple this and make it work to a certain extent its just it doesnt merge the one record, it merges them all? i only want it to merge the current record, i dont know if anyone can help me with this? i'll put the code im using in a VBA module below, if anyone can tell me what im doing wrong or has a solution i would be greatful.
:
:
:
:
: Function MergeIt()
: Dim ObjWord As Word.Document
: Set ObjWord = GetObject("C:\Documents and Settings\Administrator\Desktop\Database Project\Master Thank You Letter.doc", "Word.Document")
: ObjWord.Application.Visible = True
: ObjWord.MailMerge.OpenDataSource _
: Name:="C:\Documents and Settings\Administrator\Desktop\Database Project\Database 1.mdb", _
: LinkToSource:=True, Connection:="TABLE Main_Contracts_Database", _
: SQLStatement:="SELECT * FROM [Main_Contracts_Database]"
: ObjWord.MailMerge.Execute
: End Function
:
:
:
It appears that your mail merge source is the table that you are viewing in your Access app. You are probably navigating through your complete set of records when you are viewing in the form. When you do a merge you are telling your app to merge the complete set of records there are no filters applied. Therefore you get all the records merged.

There are probably a couple of ways arround this. I think the best way would be to make a temporary recordset or table and use that as the source of the merge. Or you could apply a filter to the current recordset and then merge it. You would have to remove the filter after the merge or you will not be able to see any more records in the form.

Hope this helps

John



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.