PDA

View Full Version : Solved: User form selection and text box deletion



FhM
10-01-2009, 06:29 AM
I am looking to create some report templates in word with 5 different statement banks on them. I would like the user to be able to select a radio button of 1-5 then the other text sections would be deleted as well as the radio buttons or a tick box above the text and when pressed the text will be deleted leaving the one statement which would be moved to the appropriate place below the static introduction.

First of all does anyone have any other ideas of how this should/could be done and if you do, any code examples would be greatly appreciated.

Thanks in advance

lucas
10-01-2009, 11:19 AM
This one is an old one that I learned from when Gerry first contributed it.

There are 3 bookmarks in the document. Go to file-options, etc. to make your bookmarks visible while editing.

When you make a selection in the userform, the other two bookmarks are deleted.

Code in the userform module most relevant.

Without actually seeing your work it is hard to do more than offer alternatives that might fit your need.

the doc is zipped as the forum doesn't accept the .dot filetype.

FhM
10-02-2009, 12:06 AM
That looks to be almost perfect for what I want thank you very much :) . I am just adjusting it for my own needs now. It's a lot simpler than I would of thought as well, but that seems to be the case with me and VBA :P

FhM
10-02-2009, 05:26 AM
Ok I have this working exactly as I want except when I put it on someone elses machine. To start with I have saved it to a normal document rather than a template. The template method does work but it is no good for me because the files are exported separately from a different program. This uses a certain naming format such as name-number-exportnumber etc and I cant expect my users to get that right through normal file > save.
The problem I have is that when it is saved as a separate document it comes up with an error because it is trying to reference code in the original template it came from but it doesnt need that anymore and just needs to run the code attached to the form!!! Very frustrating.
If anyone understands what I am raving about can the suggest anything?

FhM
10-02-2009, 06:12 AM
Here is an example I have renamed and deleted the contents and put random letters in but it should come up with an error on your system. It works on mine but if I take it elsewhere it doesn't work.

I deleted the file it references but that still did not stop it working on my system. Any help greatly appreciated as I have the code I want working but it will only work on my PC.

lucas
10-02-2009, 06:16 AM
You might give more details as I'm sure this can be incorporated into your job using the template but not with the info you have provided, it's just not enough.

To make it work as a regular word file:

open a regular word document and the go to file-open and browse to the .dot file and open it that way.

Save the file as a .dot or normal file.

In the vbe go to the thisdocument module and delete or comment out this code:

'Private Sub Document_New()
'frmDemo.Show
'End Sub


and replace it with this:
'Private Sub Document_New()
'frmDemo.Show
'End Sub
Private Sub Document_Open()
frmDemo.Show
End Sub

You will have to make a copy of this each time you use it.

see attached.

FhM
10-02-2009, 06:36 AM
I'm not sure if you saw my previous post with the file attached? I can get it working fine on it's own. I have stopped the form coming up straight away because I want them to read the text they decide and with the form active they cant scroll. I will code in a shortcut key for when they are ready to choose.
Thanks for your help it is greatly appreciated

lucas
10-02-2009, 06:39 AM
Try this, there is a new menu item to open the form if you close it before you make a selection.

Why does your file have an .xml file extension? If this is for word 2007 I can't tell you if this will work or not. I don't have 2007

FhM
10-02-2009, 06:40 AM
It is what the program exports it as. It opens fine in Office 2003.

lucas
10-02-2009, 06:42 AM
If you don't want the form to open when the file is opened just comment out the code in the thisdocument module of my file in post #8. A file menu item is added to this document alone.

How to add a menu item: click here (http://slucas.virtualave.net/Wink/CustomMenuItem.htm)

FhM
10-02-2009, 06:49 AM
Did the file I uploaded work for you? My issue isn't really when the form comes up it is when I select a radio button and press ok it comes up with an error the code is identical in that section to what you provided. I want to know why my file doesn't work because that is how they are exported from the third party program and I need it to work from them files because I will have thousands in the end.

I can get it to work on a standalone document fine. It is just when I mix it with this other one.

Thank you for you patience :)

PS the error only occurs on other systems not my own

lucas
10-02-2009, 07:10 AM
No it doesn't and I can't explain why. If I save my doc file as an xml it still works. Maybe something to do with what program you are exporting the file from, what is it?

I still think you should be able to use the template and reference it for use. You don't give enough details though.

FhM
10-02-2009, 07:31 AM
I am gonna take this home and report back on Monday. Thanks for the help so far.

FhM
10-02-2009, 08:17 AM
Ok I found for some reason it is try to reference standard code from references that are not available. If I untick the references it works fine. But I am going to have thousands of these files, so is there anyway to do it through VBA?

fumei
10-02-2009, 10:22 AM
References are a collection, and can be accessed via code.

VBE.ActiveVBProject.References

This sounds very messy though.

FhM
10-02-2009, 12:21 PM
References are a collection, and can be accessed via code.

VBE.ActiveVBProject.References

This sounds very messy though.

Yes it does. What I think I am going to do is write some code to open all the output files and copy the contents to a nice fresh file with my desired macros. Hopefully this will work as expected.

fumei
10-02-2009, 01:53 PM
That sounds like an excellent idea.

slk
10-04-2011, 02:12 PM
thanks