Merge two tables into one document?-VBForums
Results 1 to 10 of 10

Thread: Merge two tables into one document?

  1. #1

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Merge two tables into one document?

    I have two tables. One is a list of clients, and one is a list of data to be sent to all clients. I want to use Word to mailmerge the two together, except that there doesn't seem to be a way to do it!

    Any ideas on the best way to go about this? Should I create a multipage document, and then send that via mailmerge? (Can I build the mailmerge document dynamically?)

    I already have labels for the clients, so maybe I could generate the mailmerge with the data, and then dynamically add merge fields for the clients?

    I hope that I don't have to use VB to do all the merges, but that's the way I see that it can be done.

    Thanks for the help!

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: Merge two tables into one document?

    David, you can do it from either Access or Word, assuming that the two tables
    are in Access. From Access, you create a query that will give you the resulting
    recordset you want in Access. Then you can go File > Export... and select
    Save As Type box, click Microsoft Word Merge (*.txt). Then click the arrow
    to the right of the Save In box, and select the drive or folder to export to. In
    the File Name box, enter the file name, and then click Export.

    Access creates the data source containing the field names and all the data from your table.

    Also, in a word mail merge data source, the first record in the file contains
    the field names and is called the header row. All succeeding records are the
    data rows. The field names in the header record must match the field names
    in the main document. If they don't match, edit the field names either in the
    data source (you can open the data source in Microsoft Word) or in the main
    document so they do match.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  3. #3

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Merge two tables into one document?

    I was trying not to have to use Access, as I am loading tables in VB and making temporary tables. I'd like to just kind of automate Word to make it as seamless as possible. Could I do a SQL statment to make the temporary table from within VB? I'm not sure that users will have Access.

    The other problem that I had was dynamically changing the merge document in word. It seems to open the same table each time, but I need to set it the first time if I package the app. It works fine on my machine, but I need it to work when installed elsewhere.

    Thanks for your help!

  4. #4
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: Merge two tables into one document?

    I'm just getting ready to leave, but you can create an ADO recordset with the resultset you need and
    set that as the recordsource for the mailmerge in Word. You need to do a little automation of word so it knows your
    passing a prepopulated recordset for the MM.

    Be back tonight with more explaination/help.

    Yea, time to go home!
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  5. #5

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Merge two tables into one document?

    I'd like to hear more about it.
    Last edited by dglienna; Feb 9th, 2005 at 12:38 AM.

  6. #6

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Merge two tables into one document?

    time for anything else?

  7. #7
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: Merge two tables into one document?

    A little, I'm debuggin my vb.net usercontrol .

    When you say that the fields are going to be changing, do you mean the number of fields, location, or names ?
    That part will make it difficult.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  8. #8

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Merge two tables into one document?

    writing a query to include the fields that are sent out to the selected merge documents. Would it be better to have the same fields sent out each time?
    I wanted to be able to choose number of fields each time.

    If you could get me started, I'll work out the details. I'm not sure if I just make 15 records of each, and merge each with 15 people, or set up the merge document "populated" as you say that will send each record to the 15 person in the list.

  9. #9
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: Merge two tables into one document?

    Its almost time to go home so if we can figure out which way we will go with this I will try to whip up something tonight.

    I think you may be able to do it using the MM in Word as is (depending on your data and how you need it).
    You can create a query in Access that will contain a one to many relationship between your clients and data
    tables. In Word you can assign the fields for the receipient separately from the other fields in the document.
    I'm not sure if this is how you need it, but it will give you something to look into in the mean time.

    Later.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  10. #10

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Merge two tables into one document?

    I want to use SQL, not access. Don't want to requre that users have Access installed. Thanks in advance for you help. Have to spread the wealth, but I will do that tonight.

    Or do you mean to create the tables and relationships in Access? Willl I have any trouble writing to them with SQL?
    Last edited by dglienna; Feb 10th, 2005 at 12:54 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.