Results 1 to 14 of 14
  1. #1
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto create tables in Word??? (2003)

    Good day mates!

    Wrong Forum? Please move.
    Take a look at the provided WORD Document. The red fields get their data from some Access database.
    Access looks like this:
    tblSchools
    [ID]
    [School]
    [assignedCountry]

    Now the problem is, that some schools have like 3 assigned Countries, that means I have 3 times the same document (3 pages) - first problem: could maybe be done in one document.

    But now the major problem!!!!:
    Some schools are not present in all Committees (take a look at the word document to know what I am talking about). That means I have to delete the table cells on page 2+3 which do not apply and I do have to put a "----------------" in every cell on page 1 which is not appliable to the school

    Let's have an example: School XY is only present in 7 Committees, that means I have to put a "-------------" in e.g. 1st Committee and ECOSOC and I have to delete those table cells on the bottom.
    ^^Doing this for 50 schools is just a pain in the ***


    How could this be done more easily? Word is just too nice of a text-editing tool that I don't really want to change to access. If that is the only solution - please tell me.
    Attached Files Attached Files

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Auto create tables in Word??? (2003)

    Are you using the Merge feature? I think there are solutions to both of these issues in earlier merge threads, but as one who never does this himself, I haven't kept track of the details.

    On the first point, one-to-many relationships in the data source, you might try the Word FAQ on the MVPs.org site, as well as a general web search.

    On the second point, you can embed your MERGE data fields into a conditional IF field. To give you a crude idea of how this works:

    { IF MergeField1="" "--------" MergeField1 }

    I'm sure others with more merge expertise will be able to help you work through this.

    If you are not using the built-in merge feature and instead are using ADO and VBA, we should move this thread over to the VB/VBA board.

  3. #3
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Auto create tables in Word??? (2003)

    Hi,
    Based on your first question, I could propose that you create a query from the table that filters for unique records. (You can change the queries properties to be "Unique values only", or set up a DISTINCTROWS query. This should prevent your word document giving you 3 pages of the same data. If the fields in your document are linked to the database table, remember to change its source to point to the query!
    Secondly, (I agree with jscher2000) in that you must set up the fields in your document to be nested into an IF field. If the field from the database is blank (""), then it can give you the output of "---------------". (See the attachment as an example!)
    Attached Images Attached Images
    Regards,
    Rudi

  4. #4
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto create tables in Word??? (2003)

    No you were right that I was using the MERGEFIELD function.

    Well I'm familiar with the IF Function, but I'm not sure if it satifies my needs.
    The point is that I have 9 "cells" on page 2+3 (as you can see in the example). Now not every record does have ALL 9 fields - instead the record only has 6 fields.
    So what I have to do for those, not having all 9 fields is to delete those spare "cells" manually.

    I'm looking for a way to let Word create those cells based on some data in the table. So let's assume the table says "Shool X has 6 fields" and Word creates those six fields instead of all 9.

  5. #5
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Auto create tables in Word??? (2003)

    I've never attempted this using VBA code, but it should be possible so or other way!!!! I will put this post on my reminders list, look into it and supply you with an example (if I find a solution) if no one else has a easier/faster solution.
    Regards,
    Rudi

  6. #6
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto create tables in Word??? (2003)

    sounds good to me, a solution would be really helpful. A solution with VBA or with any other code would be fine, but I guess it is ONLY possible with VBA....

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Auto create tables in Word??? (2003)

    I think I remember a thread where someone put entire table rows into the output of an IF field, but it wasn't easy. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Using VBA to work with data sets and lay out documents always is hard the first time, but there are some shortcuts you can take. For example, you can save the shell of the table as AutoText so that rather than having to create it from measurements you can insert it and then position inside and start spraying data. Similarly, you know that "tabbing" from the last cell in a table row creates a new row, and you can take advantage of that in VBA, too. So you can write a "loop" that reads and types your data into the document and simply stops when the next page is supposed to start, you don't have to pre-analyze how many rows you need.

    I realize this is all rather abstract, but any example I could give you would require a great deal of sanitizing.

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Auto create tables in Word??? (2003)

    <P ID="edit" class=small>(Edited by macropod on 18-Aug-04 12:45. Edited 2nd para & added attachment)</P>Actually, putting a table into an IF statement is little different that putting text into a table. What you can't do, though, is change the number of cells on a row. You can get around that problem by putting the table into it's own multi-column section, so that the one-column table takes advantage of snaking document columns to achive a multi-column table appearance.

    The other issue you might need to deal with is that putting one or more tables into an IF statement causes the document to add an extra paragraph before the table. A possible workaround is to format the extra paragraph in a 1-pt font.

    Cheers
    PS: See attached demo.
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto create tables in Word??? (2003)

    Yeah works great, nice solution.

    I'm coming to the point where I can see that my desired solution will include a lot of programming work... I'll see if I have the time for that now. I guess for the next year the user wil still have to delete those not-wanted table cells [img]/forums/images/smilies/wink.gif[/img]

    I'll keep the demo tho to work on this some more individually.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Auto create tables in Word??? (2003)

    A macro to delete rows of blank table cells would be a lot simpler. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

  11. #11
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto create tables in Word??? (2003)

    You don't know how mugh work this was [img]/forums/images/smilies/wink.gif[/img] OK it's not just a siimple deletion process. Take a look at the tabel on the bottom. Text in brackets <> is text provided by the database. The rest is fixed text.

    Now as you can see there is Committe 1,2,4,9 - why that odd order? Well normally it's Committee's 1 though 9 with no gaps. But some schools don't send the full number of participants which makes it a must for me to delete some of those not needed Committee - cells.

    I don't delete let's say the last three, it's always something in the middle (look at the example) like delete Committee 3,5,6,7,8. I need to do this because all COmmittees should have the same number of participants, deleting just the last fields (Committees 7,8,9) would make the other committees become crowded - as easy as that.

    Now I was looking for a way to either delete those tablecells via checkboxes or something - OR to create them based on the database which COULD provide the assigned Committees

    <table width="370" border="1" cellspacing="1" cellpadding="0" height="292">

    <td colspan="2">Name:</td> <td colspan="2">Name:</td>

    <td><Country> Comm. 1
    <Year>
    </td>
    <td>Place
    Picture here
    </td> <td><Country> Comm. 2
    <Year>
    </td>
    <td>Place
    Picture here
    </td>

    <td colspan="2">Name:</td> <td colspan="2">Name:</td>

    <td><Country> Comm. 4
    <Year>
    </td>
    <td>Place
    Picture here
    </td> <td><Country> Comm. 9
    <Year>
    </td>
    <td>Place
    Picture here
    </td>
    </table>

    Don't ask me why the table is put way to the bottom.

  12. #12
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Auto create tables in Word??? (2003)

    (I also couldn't figure out why there is all that blank space above your table...)

    My mistake, I forgot it was really not a typical one-record-per-row table. You can use a one-record per row table to emulate your table by using columns (Format>Columns, not table columns), but the sequence would change from across-then-down to down-then-across.

    VBA does seem to be the best solution.

  13. #13
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto create tables in Word??? (2003)

    Hmm dunno exactly how I could emulate such a complex table structure since all cells have different heigths and so on and I don't know how to change the sequence since I don't see any options for that in the Columns menu.

  14. #14
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Auto create tables in Word??? (2003)

    While you can hardcode the height of a row (check Table>Properties...>Row tab for the current row), there's no fix for the down-then-across problem (except to change the order in your merge data source, maybe). Sorry if I seemed to be promising one.

Posting Permissions

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