PDA

View Full Version : Auto Fill identical table



larrinh
04-14-2005, 03:55 AM
I have a document in Word 2003 that has two identicle tables (one for purchasing and one for originator). Can I have the second table automatically filled in with information from the first table as it is typed or is there another way that would be better. In Excel VBA I would just get the current cell, and copy the data on the Keyup event to the target cell but I haven't figured out how to do this in Word VBA.

Any help or suggestions would be great. I've already spent too much time on this.

Thanks,
- Larrin
:dunno

MOS MASTER
04-14-2005, 11:47 AM
Hi, :D

Perhaps itt's possible to do what you want with Application Events but it will not be easy and it will slow down you're program.

Word does have controls (Control toolbar) that you can put in you're cell's that do allow events on them (Like Change Event) so you can dynamically fill one and the other gets filled. (Simple example attached)

But consider the following:
Why do you have two exactly the same tables in you're document?

You can also do the following...by the way I presume it's nessecary for you to have the second table filled in at printout or perhaps at save or closing of the doucment...(you pick)

What you could do is simply copy the contents off the first table, Select a predifined bookmark and paste the first table in you're document en that way you have exactly the same table as the first one..but in a different location in the document.

Simple code for this would look like: Sub CopyTable()
ActiveDocument.Tables(1).Range.Copy
ActiveDocument.Bookmarks("bmTable").Select
Selection.Paste
End Sub

If you'd like to take this road than we can tune this code up quit a bit so it meets you're expactations!

Enjoy! :thumb

larrinh
04-15-2005, 04:07 AM
MOS Master

I tried your example but nothing happened so I put a break point in the macro and the VBA event did not fire. Is there something I have to turn on to get VBA to work in Word?

- Larrin

MOS MASTER
04-15-2005, 09:22 AM
Hi Larrin, :D

Yes you must change the settings on Macro security.

Go to Tools/Macro/Security and put security to Medium.

Then reopen the document except macro execution.
If you see a little toolbar with a triangle on it you must press that to leave design mode..(My example should not show that if you're settings are correct...will be shown if settings are on "HIGH")

Try to put you're cursor in the first textbox and type if you're not able to enter the box you're still in designmode...

That should do it! :whip

fumei
04-15-2005, 10:19 AM
The EASIEST way to get another location to reflect the value of a previous one is:

The first location is a formfield. It is better to have it explicitly named. Say the first formfield is ClientAccountNumber.

Anywhere you want to have a copy of whatever is entered into that formfield (ClientAccountNumber), do this:

Press Ctrl-F9.
Type in the name of the field you want to have the same value.

That is it. You are done.

You can do this as many times as you like. The only caveat is that the formfield that you are picking up the value from MUST, repeat, MUST have Calculate on exit checked.

However, other than that, you can make a field copy the value anywhere you like, as many times as you like.

MOS MASTER
04-15-2005, 10:29 AM
Hi Gerry,

True..this is an easy method to achieve this kind off linkage.
But the question is for this to work the document has to be protected. (The whole doc or only the section on witch the formfields reside)

The question off course if this is workable in this case..(That's for the OP)

But if so the formfield approach is a whole lot easier to implement than my ActiveX sollution...

The copy table sollution is still a simple approach en you don't have protect the document...(Disatvantage off this approach is off course the VBA code that you would not need if using only fields)

fumei
05-02-2005, 09:36 AM
If the formfields are set to Calculate on exit, yes, using Ctrl-F9 blank fields will work fine with a protected document.

MOS MASTER
05-03-2005, 11:25 AM
If the formfields are set to Calculate on exit, yes, using Ctrl-F9 blank fields will work fine with a protected document.
Hi Gerry, :D

Missed this one yeasterday.
It does run well but I normally use Ref-fields instead (more options) But your field codes are an easy way to create a quick reference.

Toedeloe...:whistle: