PDA

View Full Version : Active X control Corruption



tla
10-21-2008, 07:58 AM
I inherited a file that uses Active X contorls in a word file, both dropdown boxes and a few buttons. IT s a template that alot of people use. Every so often something happens and a users copy gets corrupted. The NAME of every activeX control in the file is suddenly renamed.

Example was DropdownBox, suddenly it's DropdownBox1
All the names now have a "1" at the end so the code that populates the drop downs at file open pukes.

Any Idea why that may happen?

If not - Is there a way to pull the name of a given combo box without knowing it's name. Can i get the name of the 1st combo box in the document in VB, then the 2nd, etc? That way i can call for the names inside of hard coding them taht would solve the issue.

fumei
10-21-2008, 01:59 PM
I suspect there is some code that is doing some copying of the controls. This is a BAD idea. Copying controls - as opposed to creating them - can really mess up names.

Further, it is a GOOD idea to always give explicit names to controls. "DropdownBox" is not useful.

Something is not correct with this: "IT s a template that alot of people use. Every so often something happens and a users copy gets corrupted. "

Users should NEVER have a copy of a template. Ever. User use templates. Or are you talking about a document, rather than a real template?

Or...are you saying that a user does indeed clone a new document from the template, and the ActiveX controls are renamed?

"All the names now have a "1" "

Are you saying that you have multiple comboboxes - and BTW ActiveX controls are ComboBoxes....not Dropdowns. Dropdowns are formfields - with the SAME name?

tla
10-23-2008, 06:31 AM
Let me try to explain this again- it was a little muddled there.

THis is a word doc stored on a shared drive that lots of people copy down and use as part of a process (though they don't know the location of the original file and can't manipulate it). They then fill out and manipulate various aspects of their copy of the word doc (not strictly a "template"). Upon opening, the program does populate the combo boxes with data (.Additem commands), but does not copy or create them. There are also two buttons tied to macros (that add blank lines to tables and number those tables once filled in based on certain criteria).

A couple of people have come to me with non wokring files, and the problem was the same. All of the contorls (comboboxes and buttons) in the word document were renamed with a "1" at the end. All controls have good names, i just used "dropdownbox" as a generic example to illustrate the point.

I have tried to recreate the problem to no avail. I can't figure out how the controls would all suddenly be renamed. It seems like a networking/cpu problem when saving it - sometimes the network is slow and some CPUs here have sever memory deficiencies, but I am stumped.

Whenever I try to repair one of the broken files by renaming the contorls back (to try to save the person's work on the file) Word (2002) errors and shuts down.

I could solve this by reowrking the program if I could pull the names of the combo boxes when pulling the macro, but I can't see a way to do that. Is there a way to get the name of combobox 1, 2, 3, etc from a document? in the VBA code. I looked at this and seems something like contorls(1).name would give it to me but it errors.

fumei
10-23-2008, 09:00 AM
"I looked at this and seems something like contorls(1).name would give it to me but it errors."

What error?

If I understand what you are describing - and I may not fully - this is not a very good way of doing things.

However, ignoring that, yes, there is a way of getting the names.

ActiveX controls like comboboxes, textboxes etc. are InlineShapes. Unless of course you changed them into Shapes.

Dim oCtl As InlineShape
For Each oCtl In ThisDocument.InlineShapes
MsgBox oCtl.OLEFormat.Object.Name
Next

If the above is in the ThisDocument module, it will return the names (in the order in the document!) of each InlineShape.

Now, of course if you have OTHER kinds of InlineShapes you will get them as part of the InlineShapes collection.

Attached is a demo of this. Click the commandbutton with the caption Click Me. It will display a messagebox with the listing of controls, in order, including the commandbutton itself.