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 / April 2007

Tip: Looking for answers? Try searching our database.

Checkbox control change bypassing ThisDocument.Saved

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TheMarioInc - 12 Apr 2007 14:24 GMT
Hello,

I have created a one page "checklist" consisting of a few tables for a
user to enter information, as well as four checkboxes from the Control
Toolbar.  I have my own FileSave and FileSaveAs macros to force the
user into entering some information prior to saving the document.

I also used Document_Close to bypass the generic "Do you want to save
changes..." prompt.  If ThisDocument.Saved is false my Yes/No/Cancel
box appears.

Yes - call my FileSave macro
No - set ThisDocument.Saved to True (to bypass the built-in "Do you
want to save changes..." prompt and exit)
Cancel - send Esc

All of this worked well until I added the checkboxes.  If the user
makes a change to a table cell (e.g. they enter their name), and tries
to close the document without saving, my prompt appears.  If they
click No, the document closes (no further questions asked).  If they
click one of the checkboxes and try to close the document, my prompt
appears.  After clicking No, the built-in "Do you want to save
changes..." appears even if ThisDocument.Saved is set to True by the
prior "No" click.  How do I prevent a change to the checkbox from
causing Word to prompt the user to save with its own dialog box?

Private Sub CheckBox1_Click()
   ThisDocument.Saved = False
End Sub

Private Sub Document_Close()
   ...

   ' Present the user with custom options if an attempt is made to
close the
   ' document without saving
   If Not ThisDocument.Saved Then
       intMsgBoxResult = MsgBox(strFileName & " has changed. Save the
change(s)?", _
                                vbYesNoCancel + vbQuestion,
"Checklist")
       If intMsgBoxResult = 6 Then 'Yes
           ' Ensure that if the user choses to save the document that
the Name field is populated
           If strName = "" Then
               intMsgBoxResult = MsgBox("Please enter a Name prior" _
                                        & " to saving the document.",
vbCritical, _
                                        "Checklist")
               SendKeys "{ESC}"
               ThisDocument.Bookmarks("YourName").Select
           Else
               Functions.FileSave
           End If
       ElseIf intMsgBoxResult = 7 Then 'No
           ' Prevent Word's default "save changes" prompt from
activating
           ThisDocument.Saved = True
       ElseIf intMsgBoxResult = 2 Then 'Cancel
           ' Word's default "save changes" prompt will become
activated, but
           ' close immediately
           SendKeys "{ESC}"
       End If
   End If

End Sub

Thanks,
Mike
Cindy M. - 18 Apr 2007 17:27 GMT
Hi TheMarioInc,

I don't really have an answer for you, but I do have an observation that
might help lead you to a solution...

The ActiveX controls' macros run asynchronously. If you're not really
careful, you can get into all kinds of conflicts that will result in
endless loops. I suspect this may be affecting your code, although I
immediately see the "how".

Possibly, something in the document close process is "tickling" the
checkbox controls, causing them to be dirty. I know that happens with
Office 2007 content controls...

If you comment out the code in a checkbox procedure does the behavior go
away?

> I have created a one page "checklist" consisting of a few tables for a
> user to enter information, as well as four checkboxes from the Control
[quoted text clipped - 61 lines]
>  
> End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :-)
TheMarioInc - 19 Apr 2007 17:35 GMT
Hi Cindy,

The only code I added for the checkbox is to set ThisDocument.Saved =
False.  This was added after I discovered that ThisDocument.Saved
remained True after clicking on a checkbox to change its state.  My
custom prompts and save macros are skipped over unless the value of
Saved is False.

I went ahead and created a version of the checklist document that does
not contain the checkbox controls.  The user types something into the
"Check Mark" table cells such as 'x', or "Yes".  Prior to saving the
document, the non-empty table cells are replaced with a lower-case
'x'.  Using the Wingdings font makes it appear as a stylized 'x'
inside of a box.  It gets the job done.

Thanks,
TheMarioInc

Rate this thread:






 
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.