Results 1 to 11 of 11
  1. #1
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Template - Data lost on Print (Word 2003)

    Hi There

    I have developed a lot of templates for use in our department and until we recently updated to Office 2003 they worked fine. It seems now, for some reason staff are having an issue where there data is lost on Printing. I think I am sure that this happens because they unlock the form and dont relock it before printing. I know in the older version of word, all data was lost if the user unlocked and locked the template. I overcame this with the use of a macro I found on the MVPS site.

    The only option I can think of is to get a macro that relocks the template on hitting the print button. But it only needs to be relocked if it has been unlocked, if you know what I mean.

    Does anyone have any other ideas or had this problem too?

    Kerry

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Template - Data lost on Print (Word 2003)

    I haven't tested any Word forms in Word 2003. Because the protection was made more granular (you can protect areas smaller than an entire section), it's possible that older unprotect/reprotect code will not work quite the same. Hopefully you can get onto one of the computer that has a problem and figure out what is causing it.

  3. #3
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Template - Data lost on Print (Word 2003)

    Are you able to assist me in writing a macro to unlock on printing if it has been unlocked?

    Kerry

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Template - Data lost on Print (Word 2003)

    Something like this? It seems to work in Word 2002, which is the only platform available to me at the moment:

    <code>Sub FilePrint()
    ' Protect (if needed), Print dialog, Unprotect (if needed)
    Dim lngProtected As Long
    lngProtected = ActiveDocument.ProtectionType
    If lngProtected = wdNoProtection Then 'Protect for forms
    'MsgBox "Protecting!"
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    End If
    Dialogs(wdDialogFilePrint).Show 'Show Print dialog
    If ActiveDocument.ProtectionType <> lngProtected Then
    ActiveDocument.Unprotect 'Restore unprotection
    End If
    End Sub</code>

    The choice of name for this macro is significant: using FilePrint will "hijack" the built in FilePrint command. Note that the toolbar button that bypasses the dialog calls FilePrintDefault, so you might need to address that one, too, perhaps changing the middle of the macro as follows:

    <code>Sub FilePrintDefault()
    ' Protect (if needed), Print dialog, Unprotect (if needed)
    Dim lngProtected As Long
    lngProtected = ActiveDocument.ProtectionType
    If lngProtected = wdNoProtection Then 'Protect for forms
    'MsgBox "Protecting!"
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    End If
    ActiveDocument.PrintOut 'Print doc without dialog
    If ActiveDocument.ProtectionType <> lngProtected Then
    ActiveDocument.Unprotect 'Restore unprotection
    End If
    End Sub</code>

    I didn't test that second one because I've removed that toolbar button. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  5. #5
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Template - Data lost on Print (Word 2003)

    Thanks Jefferson.

    Option 2 works! It was a good thing I asked for help, I would never have known the issues you pointed out.

    I have still retained the spellcheck macro as it appears Microsoft still havent resolved the issue of not being able to perform a spellcheck in a locked template.

    Thanks again
    Kerry

  6. #6
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Template - Data lost on Print (Word 2003)

    oops I think I jumped in a bit quick. While it works on the print icon. It doesnt when the person choses File Print and you betcha someone will do that. HELP

    I removed the line ActiveDocument.Unprotect 'Restore unprotection as I wanted it to remain locked after printing.

  7. #7
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Template - Data lost on Print (Word 2003)

    Hi Kerry,

    I am taking a wild chance here, and chances are that it may not work, or work out of context, but as Jefferson is not around at the mo....., why not give this a try. I am aware that in Excel, you can cancel events before they occur by typing Cancel = True in the appropriate Before Event. I found this example in the word help files which tells me that word has a Document BeforePrint event. And there is a Boolean argument in the event that allows the event to be cancelled. The Word help files shows this example:

    Public WithEvents appWord as Word.Application
    Private Sub appWord_DocumentBeforePrint _
    (ByVal Doc As Document, _
    Cancel As Boolean)

    Dim intResponse As Integer

    intResponse = MsgBox("Have you checked the " _
    & "printer for letterhead?", _
    vbYesNo)

    If intResponse = vbNo Then Cancel = True
    End Sub


    If you change it to the following below, it may <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15> just cancel the print event if the person uses the Menu Print command...its worth a shot!

    Public WithEvents appWord as Word.Application
    Private Sub appWord_DocumentBeforePrint _
    (ByVal Doc As Document, _
    Cancel As Boolean)

    Cancel = True

    End Sub
    Regards,
    Rudi

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template - Data lost on Print (Word 2003)

    If you use code like the above (which *must* go into a class module, not into a standard module), you must also initialize the appWord variable. See the help subject "Using events with the Application object".

  9. #9
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Template - Data lost on Print (Word 2003)

    OK...this is something I have never done before...Class Modules and the like. Sorry for posting incorrect data. (I guess my "shot" recoiled quite badly!)
    Regards,
    Rudi

  10. #10
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Template - Data lost on Print (Word 2003)

    I am a little confused.

    What do I have to do to get Jeffersons suggestion working when the user uses the File Print Option?

    Do I still use Jeffersons Macro for the Print button?

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Template - Data lost on Print (Word 2003)

    You need to put both the FilePrint and the FilePrintDefault macros in a module. The first one will hijack the File | Print... menu option, and the second one the Print button on the Standard toolbar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •