Code changing control name

D

David B

I have developed a form in Word. On the form there are two command buttons.
Each one, when clicked, inserts a new row into two different tables. The code
for each button is identical except that each points to a different table.

When I press one button it does what I want, however, somehow it renames the
other command button. When it does this, the other button is unable to find
its sub procedure and therefore no longer works.

I have not coded the button to do this.

Does anyone know why this might be happening?
 
A

Anand.V.V.N

Hi David

If you can post what code you have written, it could be easy to figure out
what is happening.

Anand
 
G

Greg Maxey

"Who will guard the guards?"

I'm considering it. Can you provide more information on base salary
and the fringe package?
 
D

David B

Thanks Anand...here is the code:

Private Sub cmdAddTargetItem_Click()

'This sub procedure inserts a new row into the Target Item table. The
procedure unlocks
'the document, makes the change, then locks it again

'unlock document if protected
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="password"
End If

Selection.GoTo What:=wdGoToBookmark, Name:="P4"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk 'wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.InsertRows 1
Selection.Collapse Direction:=wdCollapseStart
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Selection.Copy
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Paste

'lock document if unprotected
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="password"
End If

End Sub

'----------------------------------------------------------------------------------------------------

Private Sub cmdAddDragItem_Click()

'This sub procedure inserts a new row into the Drag Item table. The
procedure unlocks
'the document, makes the change, then locks it again

'unlock document if protected
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="password"
End If

Selection.GoTo What:=wdGoToBookmark, Name:="P6"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.InsertRows 1
Selection.Collapse Direction:=wdCollapseStart
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend
Selection.Copy
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Paste

'lock document if unprotected
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="password"
End If
End Sub

When the first sub procedure cmdAddTargetItem_Click() is run, it changes the
name of the command button cmdAddDragItem by adding a "1" to the end of its
name, for example, from cmdAddDragItem to cmdAddDragItem1.
Each time the procedure runs it appends another 1.

I hope this helps.

David
 
A

Anand.V.V.N

Hi david,
I executed your code, there seems to be no problem as such, but I'll go
throguh it once again and let you know.

Anand
 

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