Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VBA - Mail Merge Access to Word Template

Jademonkey2kJademonkey2k Posts: 1Member
[b][red]This message was edited by Jademonkey2k at 2005-1-20 9:56:53[/red][/b][hr]
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 SettingsAdministratorDesktopDatabase ProjectMaster Thank You Letter.doc", "Word.Document")
ObjWord.Application.Visible = True
ObjWord.MailMerge.OpenDataSource _
Name:="C:Documents and SettingsAdministratorDesktopDatabase ProjectDatabase 1.mdb", _
LinkToSource:=True, Connection:="TABLE Main_Contracts_Database", _
SQLStatement:="SELECT * FROM [Main_Contracts_Database]"
ObjWord.MailMerge.Execute
End Function


Comments

  • jlegjleg Posts: 237Member
    : [b][red]This message was edited by Jademonkey2k at 2005-1-20 9:56:53[/red][/b][hr]
    : 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 SettingsAdministratorDesktopDatabase ProjectMaster Thank You Letter.doc", "Word.Document")
    : ObjWord.Application.Visible = True
    : ObjWord.MailMerge.OpenDataSource _
    : Name:="C:Documents and SettingsAdministratorDesktopDatabase ProjectDatabase 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 ;-)
Sign In or Register to comment.