ActiveX Control works in .dot, only one time in .doc

S

SGagnon

Hello:

I have a .dot with a couple of tables in it.
There are ActiveX buttons in the form to add/remove rows from the table.

The Add button resides inside a cell in the last row in the table. The
Remove button is in the header row. Each row in between contains an ActiveX
checkbox to mark it for removal.

If, while working on the .dot, I protect the form, I can then click on the
Add/Remove buttons repeatedly and it all seems to work. The logic for
adding/removing toggles the protection on the form before & after making the
addition/removal.

If I protect the .dot and save it, and then use it to create a .doc: The
ActiveX button logic works one time only. The second click of the button
yields nothing.

I thought that perhaps it was a password problem, but the same thing happens
whether there is a password or not.

Below is the code for the Add button, and the ToggleProtection method.

Can anyone see anything wrong offhand, or can you tell me how I might debug
this?

Thanks for your help.
Suzanne.

----------------
Private Sub AddDepRow()

Dim ffPartNum, ffCkChg, ffPartDesc As FormField
Dim rngCell As Range

ToggleProtection

Selection.Tables(1).Rows.Add BeforeRow:=Selection.Rows(1)
vNewRowIndex = Selection.Tables(1).Rows.Count - 1

With Selection.Tables(1).Rows(vNewRowIndex)
.Borders.OutsideLineStyle = wdLineStyleDouble
.Borders.InsideLineStyle = wdLineStyleSingle
.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
End With

Set rngCell = Selection.Tables(1).Rows(vNewRowIndex).Cells(1).Range
rngCell.Text = ""
rngCell.Collapse

Set ffPartNum = ActiveDocument.FormFields.Add(rngCell,
wdFieldFormTextInput)
ffPartNum.Name = "txtDepPartNum"

Set rngCell = Selection.Tables(1).Rows(vNewRowIndex).Cells(2).Range
rngCell.Text = ""
rngCell.Collapse

Set ffCkChg = ActiveDocument.FormFields.Add(rngCell,
wdFieldFormCheckBox)
ffCkChg.Name = "ckDepChg"

Set rngCell = Selection.Tables(1).Rows(vNewRowIndex).Cells(3).Range
rngCell.Text = ""
rngCell.Collapse

Set ffPartDesc = ActiveDocument.FormFields.Add(rngCell,
wdFieldFormTextInput)
ffPartDesc.Name = "txtDepDesc"
ffPartDesc.ExitMacro = "OnDepDesc"

Set rngCell = Selection.Tables(1).Rows(vNewRowIndex).Cells(4).Range
rngCell.Text = ""
rngCell.Collapse

Dim oleCB As InlineShape
Set oleCB =
ActiveDocument.InlineShapes.AddOLEControl("Forms.CheckBox.1", rngCell)
With oleCB.OLEFormat.Object
.Caption = ""
.Width = 12.75
.Height = 14.25
End With

ToggleProtection

Selection.Tables(1).Rows(vNewRowIndex).Select

End Sub

----------------------
Sub ToggleProtection()
'
' ToggleProtection Macro
' Macro created 3/31/2004 by Suzanne
'
With ActiveDocument
If .ProtectionType = wdNoProtection Then
.Protect noreset:=True, Type:=wdAllowOnlyFormFields
Else
.Unprotect
End If
End With

End Sub
 
C

Cindy M -WordMVP-

Hi SGagnon,
If, while working on the .dot, I protect the form, I can then click on the
Add/Remove buttons repeatedly and it all seems to work. The logic for
adding/removing toggles the protection on the form before & after making the
addition/removal.

If I protect the .dot and save it, and then use it to create a .doc: The
ActiveX button logic works one time only. The second click of the button
yields nothing.
Code for ActiveX controls can be tricky, because they reside in the actual
document, while the code behind them (Click event handler, for a button) is
usually in the ThisDocument module... in this case, of the template on which
the document is based.

You might want to try putting MsgBox statements at the beginning of every
procedure involved, so that you can if any of them are even firing.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
S

SGagnon

Thanks so much for your input.
I will try that. In the interim, I had to get the form finished, so I
replaced the ActiveX checkbox that
gets added to each row programmatically with a regular old form checkbox.
It doesn't look as cool,
but it works for now.
What you say makes a lot of sense. If I am adding the ActiveX checkbox
programmatically in the .doc
file, the ThisDocument at that time is the .doc, not the .dot... and the
..doc has no code in it. ?

-Suzanne.
 
C

Cindy M -WordMVP-

Hi SGagnon,
I will try that. In the interim, I had to get the form finished, so I
replaced the ActiveX checkbox that
gets added to each row programmatically with a regular old form checkbox.
It doesn't look as cool,
but it works for now.
What you say makes a lot of sense. If I am adding the ActiveX checkbox
programmatically in the .doc
file, the ThisDocument at that time is the .doc, not the .dot... and the
..doc has no code in it. ?
Exactly :) I wrote an article on ActiveX controls that's on the MSDN site.
The topic about code firing is touched on, although I don't know whether it
handles exactly what you're trying to do.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top