PDA

View Full Version : [SOLVED:] Populating Word Tables and Error Message



Iris
02-10-2015, 06:02 PM
Hello Again,

I working on my next template, however, have two issues:
1. Error message - I have referred back to previous template and copied the code however do not understand why I am gettting the attached error message.

2. I would like to be able to populate a number of tables/fields in the word document, the amount of tables/fields required would depend on how many lenders are selected from ListBox2. I created the Lender table and the fields in the user form but don't know how to make this to display more than one table/fields if more than one lender is chosen. And then I don't know how to populate the multiple tables/fields in the word document.

The idea is if two or more lenders are chosen then the author can add details for each lender to the specific table and add details for each lender to the fields of Conditions Precedent, Ongoing Requirements, Strengths and Weaknesses. This information is then automatically populated to the document. Apologies but I can't work out if I have set up the userform correctly or where to start with the coding.

Are you able to assist - document attached (with code).

Thank you

gmayor
02-11-2015, 12:16 AM
You are getting there :). There is little wrong with your code, but you have made a few simple mistakes. Most relate to names used in the userform that doen't match the names you address in the code e.g. the DTPicker was called OfferDate in some places (including the bookmark name) and the ListBox2 is called RecommendedLender in others. The element names must match the names in the calls to those elements.

If you use debug > compile project the problem lines will be selected.
You may find http://www.gmayor.com/BookmarkandVariableEditor.htm useful when reviewing what is in your document.

I have fixed the most obvious errors - compare it with your original. You still have to match the other fields in the form to the document.

Iris
02-16-2015, 05:32 AM
Thank you again for your previous help. My form has advanced, however, I am now up to populating the table based on the fields in the user form (Lender Table). I have had a look at your website and copied some of your code however I am obviously missing something as I'm now getting a run time error 91 - Object variable or with block variable not set. This appears on the line
For lngIndex = 1 To oCol.Count

I can't see what I'm missing when I compare to your code - gregmaxey.mvps.org/word_tip_pages/repeating_item_lists.html. Can you please assist?

The long term aim of my table is that if the author of the letter selects more than 1 lender from the LendersBox (as this is a multiple selection) that they can generate tables for each lender. Am I setting the form up correctly to achieve this??

Thank you again :-)

gmayor
02-16-2015, 06:41 AM
There are several issues. The particular error you quote relates to the fact that the macro doesn't know what oCol is because you haven't defined it. You have declared it as a Collection variable, but not given it a value to work with.

You have also built and attempted to populate a new table, before you have entered the values in the userform. The table creation and its content must go after the lines



.Show
If .Tag = 0 Then GoTo lbl_Exit

when those values are available. .Show is what displays the form and it stays displayed until you click one of the buttons that hides it.

Greg Maxey and I may sometimes work together and we may have the same initials, but we are different people. The link you quoted is to his code and not mine.

Iris
02-16-2015, 08:16 PM
Thank you for the advice and my apologies for the confusion with names, I hope I haven't offended. Think my brain was scrambled with the hour ogf the night and too much code!