PDA

View Full Version : Preventing Form Fields from Resetting to Default Values



jasoncw
07-31-2007, 12:19 PM
I searched the site on this and found this thread:

http://www.vbaexpress.com/forum/showthread.php?t=6444

However, it does not appear to be working for me. Upon printing, I am intercepting the FilePrint and FilePrintDefault events, so that some items can be hidden before printing. My code looks like this:
Sub FilePrint()
'
' FilePrint Macro
' Prints the active document
'
If ThisDocument.ProtectionType = wdAllowOnlyFormFields Then _
ThisDocument.Unprotect
Call HideShapes
Dialogs(wdDialogFilePrint).Show
Call UnhideShapes
ThisDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End Sub

Sub FilePrintDefault()
'
' FilePrintDefault Macro
' Prints the active document using the current defaults
'
If ThisDocument.ProtectionType = wdAllowOnlyFormFields Then _
ThisDocument.Unprotect
Call HideShapes
ThisDocument.PrintOut
Call UnhideShapes
ThisDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End Sub

Sub HideShapes()
'hides command buttons and text boxes for printing
With ThisDocument
.Shapes(1).Visible = msoFalse
.Shapes(2).Visible = msoFalse
End With
End Sub

Sub UnhideShapes()
'unhides command buttons and text box
With ThisDocument
.Shapes(1).Visible = msoTrue
.Shapes(2).Visible = msoTrue
End With
End Sub
The form fields actually reset themselves before printing, so when the document is printed, only the default values are printing.

I'm sure this is a simple oversight on my part. Any help would be appreciated.

Jason

fumei
07-31-2007, 12:37 PM
Could you describe precisely your document?

If it is a regular ActiveX control (like a commandbutton) in the document, then With ThisDocument
.Shapes(1).Visible = msoFalsereturns an error, as these are NOT Shapes. They are InlineShapes. Did you turn them into Shapes?

I made a document with commandbutton and textboxes, and your code fails trying execute .Shapes(1).Visible = msoFalse.

fumei
07-31-2007, 12:54 PM
Ah, I see. You made another post in the other thread. You inserted the InlineShape (the commandbutton) into a Shape (one of those horrid, horrid, horrid textboxes). Then yes, you can use the .Visible property.

I can not duplicate this. In my document NoReSet works fine. I put default text into the formfields, changed it, ran FilePrint and it printed (not showing the buttons), and the formfields retained the new text I had put in. They did NOT reset to the default.

While it is true that the buttons do not print, the space they occupy is still there. The not Visible textboxes still take up the same space. They are just not visible. Looks weird to me.

The Hidden font way at least brings the visible text in line with the rest of the document. But hey, if you don't mind the empty spaces....

I am sorry, I can't help. Your code works for me.

jasoncw
07-31-2007, 01:47 PM
Thanks for the reply, Gerry. And sorry for the confusion. I know you looked at my file the other day, and it had a little different setup.

After having a few others test out the document, it appears to be working fine for everyone except me... :(

Jason

fumei
08-01-2007, 10:37 AM
Can you post your actual file?

jasoncw
08-02-2007, 05:37 AM
Sure. You will probably have the same result as everyone else; it will probably work. But it is worth a shot. :)