PDA

View Full Version : Interesting hidden fields issue



SilverSN95
01-05-2011, 08:47 AM
Hello,

I have run into a bit of a dilemma while adding some extra functionality to a word form/document, and I’m a bit stuck on how to solve it. Unfortunately I cannot provide the document but hopefully the description will give a good idea of the problem.

The document I am working with is intended to be used as a template which can change in both structure and syntax depending on the users needs. Many sections of the document need to be “removable” depending on the need, and to accommodate this I have inserted checkboxes that will hide/unhide the text in that particular bookmark range. This makes it easy for the user to run through the document and remove sections that are not needed, and re-enable later if need be.

The issue is this: to the user it is much cleaner if by default their application does not show hidden text. When a section is hidden, to their eyes it will just collapse out of view. However, I do not want the checkboxes that control this show/hide to print. In essence, I need them hidden as well, but if I hide them the user will not see them by default… so here lies the dilemma.

The only solution I could think of is to run a macro before printing that sets all of the checkboxes to hidden, which would work, but I cant figure out how to then unhide them once printing finishes.

Is there a way to run a macro once printing finishes or maybe a more elegant solution?

Thanks.

Tinbendr
01-05-2011, 08:58 AM
I always prefer userforms. Then, the checkboxes will not be in the document.

Seems we worked on a project similer to this ~6 months ago. Search for it.

David

fumei
01-05-2011, 10:40 AM
I would agree with David. If possible, use a userform instead.

If your print job is basic, then make it part of a procedure.
Sub YaddaPrint()
' instruction to hide stuff
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
' instruction to unhide stuff
End Sub
Using whatever parameters of the print instruction that is appropriate.

SilverSN95
01-05-2011, 01:57 PM
I looked into this some more and I'd have to agree now that a userform is the best option. One thing that I am having trouble finding how to do: I need the user to be able to see the changes in real time as they edit the form, which is one reason it was nice having the controls right next to their corresponding bookmarks. Right now no changes are applied visually to the document untill I close the form.

Is there something I can do with screenupdating or something similar so the user sees these changes while using the form?

Thanks again.

fumei
01-05-2011, 02:33 PM
No, not really. The userform has the focus.

"I need the user to be able to see the changes in real time as they edit the form," Except if it is being done via logic on a userform they are not, in fact, editing in real-time.

SilverSN95
01-13-2011, 01:26 PM
Ok, so my form is pretty much built up the way I want it and it will show/hide the certain parts of the document I needed to allow control over. This solution works much better than what I was originaly trying.

One more question that I have not been able to find a solution for: Is there an easy way to save the state of my userform between opening/closing the document (e.i. checkbox and dropdown values)? I've found that in excel a common solution is to add a new worksheet to store/load the values from, so I guess I can try to mimmick this in Word on an extra page. I'm hoping there might be an easier way to do this though.

I find it odd that there isnt a way to save the userform state (like an object), is this by design or just a limitation of the app?

Tinbendr
01-13-2011, 02:43 PM
One way, use document variables. Save the ListIndex values. E.g. "1,3,5" as a string variable then use Split() to parse them and reset the form.

David

fumei
01-17-2011, 10:31 AM
When you close the document, you must also close (unload) the userform. It is destroyed. There is no state to be preserved. However, as Tinbendr suggests, values of things can be preserved using document variables. In fact, that is their purpose - to retain values of userform controls and/or module level procedures (among other things).

SilverSN95
01-28-2011, 02:39 PM
Thank you again for the help, the document variables worked for what I needed to preserve, and I’m glad I know about them now for future projects.

I’m hoping I can ask for one more favor with this. I’m trying to understand what is happening to the userform, document variables and macros when I save this document as a template. When I save the document as a template, and click new (or double click) the file seems to work as intended, but when I close it I am prompted to save two documents, the “document 1” as well as the original document and I do not understand why the original document is opening. I can tell something is going on here because my toolbar icon (which is added on new or open) is being added twice when clicking “new” on the template. If I right click the original .doc document and click new, it correctly adds one icon (so I know that macro only ran once) and when I close it I only get one prompt to save, which is what I would expect. Will I need to make some sort of template for these so other users will be able to use this document in template form?

Thanks.

Edit: I think I've narrowed down the issue to the document variables. It looks like If I dont save the second prompt then the state of the userform is lost when I re-open the document created from the template.