Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Problem with protected-form checkbox on single row of table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dylan - 20 May 2008 14:52 GMT
I have a protected table of two rows with one row headings, the next row
contains a checkbox to allow the user to strikeout text in the adjacent cell.
The problem is that the cell containing the checkbox doesn't lose its focus
to enable the event to be initiated.

Since the document is protected and only one cell is active on this table,
whenever I select one of the other cells in the table, the focus returns to
the cell containing the checkbox.

The code I'm using, courtesy of Jean-Guy Marcil:

ToggleStrikeThru Selection.Range
   ActiveDocument.Tables(1).Rows.Last.Select
End Sub
Sub ToggleStrikeThru(rngStrike As Range)

On Error Resume Next
Application.ScreenUpdating = False

If ActiveDocument.ProtectionType <> wdNoProtection Then
 bProtected = True
 ActiveDocument.Unprotect Password:=""
End If

   With rngStrike.Rows(1)
   .Cells(1).Range.Font.DoubleStrikeThrough = Not _
       .Cells(2).Range.FormFields(1).CheckBox.Value
       '.Next.Select
   End With

'Reprotect the document.
If bProtected = True Then
 ActiveDocument.Protect _
 Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If

Application.ScreenUpdating = True

End Sub
Jay Freedman - 20 May 2008 16:47 GMT
Hi Dylan,

There's nothing wrong with the code. It's just the nature of protected forms
and exit macros: The selection can't go anywhere, and the exit macro won't
fire, if there is no other form field for the cursor to go to.

The solution (which I've just verified) is to insert another form field -- a
check box or a text field will do -- in the same cell next to the first one,
and format it as Hidden text. The cursor can still jump to it, even though
it's hidden, and that will trigger the macro.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> I have a protected table of two rows with one row headings, the next
> row contains a checkbox to allow the user to strikeout text in the
[quoted text clipped - 35 lines]
>
> End Sub
Dylan - 20 May 2008 17:41 GMT
Thanks Jay, it works a treat.

I added ActiveDocument.FormFields("Hidden01").Select to my code to make it
select the hidden formfield before ending the macro.

I may go back and include this to all checkbox fields.

Regards
Dylan

> Hi Dylan,
>
[quoted text clipped - 46 lines]
> >
> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.