PDA

View Full Version : how to prevent user from deleting textboxes



onlyinameric
08-03-2006, 06:40 AM
Hi, first time user here. word 2003 VBA.

I have a template. In this template I have a table. In this table I've placed textboxes. Each textbox is linked to start the same macro by double clicking any of the text boxes. The macro pulls up a userform that contains empty textboxes, listboxes, buttons, labels needed for filling out the template. The user types in the information into those textboxes, selects from the pulldown and depresses enter. The macro then updates all the textboxes on the original template document with that information and closes. Any double clicking on the textboxes in the template opens up the userform again.

I need to prevent the user from entering the design mode AND any deleting of those text boxes. Note: I do not want to protect the document as it disables too many controls such as drawing.:dunno

hope you can help.
Regards,
onlyinamerica

fumei
08-03-2006, 11:59 AM
1.. I take these are ActiveX controls (textboxes)? In future, you should always state - especially when mentioning "textboxes" - what KIND of textbox.

2. Please expand on why you do not want to use protection. If these are ActiveX controls, you can still double click and fire your code. What is the problem? What is going on that you need drawing?

3. Textbox IN a document are meant for user input. In fact all textboxes (except those awful Insert > Textbox crap) are meant for user input. If the user is not going to be entering stuff into the textbox IN the document, it may be better to not use textboxes in the document. Bookmarks would be good. There are other ways to fire up the userform.

4. There is no way to truly prevent a user from getting into design mode and deleting the textboxes (which I don't think you need to be using). Yes, you can try, but if someone really wants to...they can. The only way is to disable the command. That is, unless you protect the document.

onlyinameric
08-03-2006, 12:44 PM
Hi Fumei,

thanks for the feedback. yes. they are activeX. I don't want to protect it as I need the drawing canvas. I want to gain complete control over the first page, headers and footers while allowing the user complete functionality throughout the rest of the document BUT I want him to be able to change some of the information within the first page, headers and footers. make sense?:bug:

the drawing package is necessary for the users to be able to create their documents. without it their work will make no sense. I can't handcuff them for that but yet I don't want them to change my layout/form hence the activeX userform.

If I could protect the document while allowing the drawing package and many of the other features to be function that would be great BUT that doesn't seem to be the case. I wanted to maybe protect my form while allowing them access to the data via the userform. no way?:dunno

thanks

fumei
08-03-2006, 03:13 PM
the drawing package is necessary for the users to be able to create their documents. I'm afraid you are going to have to explain that one. Drawing package to create their documents???? What does that mean?

You have conflicting requirements. If you have complete control of first page, header/footer, then you do. If the user can change things there...you don't. Which is it?

You can separate first page with a Section break and protect just that Section. No user changes. If you still want to allow user changes, make a menu item to fire a macro that will unprotect that first page section, allow user changes, then protect it again. However, of course if you do that...there is not much point in protecting it. Again, if the user can change things...then they can change things.


I don't want them to change my layout/form hence the activeX userformI do not understand why you think having the userform affects the ability of a user to change layout etc.

I wanted to maybe protect my form while allowing them access to the data via the userformAgain, this is cross purposes. You can protect the form and allow access to data via the userform. However, that is NOT what you are saying. You are saying they DO have access to the form, then CAN change it.

How are you firing the userform?
Is this a template - you did not answer.
What are they doing with the drawing toolbar?
Why are you using ActiveX textboxes in the document, when you are - it seems - populating them from the userform? Again, textboxes are for the user to input text, not just to hold text.

onlyinameric
08-04-2006, 06:59 AM
let me try to explain things. I'm creating a template that I give to the engineers who write processes/procedures that explain how to build our widgets. Within these procedures they need pictures with arrows they may take on their camera or draw themselves. Then they add around those pictures; arrows, circles, textboxes, colored lines, rectangles, etc helping make the explanation that much easier. Hence, why I need the drawing package available. If I protect it, they won't be able to create a well explained document as they could.

Now, on this template :thumb , the first page as well as the headers and footers of all remaining pages need to be preventative of the engineers changing my format yet allow them to enter their initials, document number, description, signatures, dates, etc. The activeX userform, if anything, is a nice professional way of inputting all of their data and is why I chose that format. I want them to change the data but not the formatting and any references I have associated.

They activate, pull up, the userform by double clicking in any area where data needs to be inputted. In each of these areas where they are going to type in data I have an empty textbox that I created from the design mode toolbar. When they double click it, I pull up the userform and they enter the data. When they are done filling in the information on the userform they click 'ok'. I then take the data they just entered and put that data into the empty textbox they just double clicked hence updating the document.

What I don't want is any of the engineers modifying the size of boxes, tables, refererences, fonts, lines, etc in those areas for me. I need all these documents to look the same from a formatting point of view.

The section breaks with protecting and unprotecting is a good idea except I need to keep the drawing toolbars active along with many of the other formatting toolbars.

you said:
I do not understand why you think having the userform affects the ability of a user to change layout etc.

I don't think that. I wrote this inquiry because I want to PREVENT the user from changing my format/layout/lines/whatever.

In a nutshell, how do you prevent the user from deleting, changing, editing a specific table, reference, textbox, footer, header, section while still allowing them total functionality within Word for all other areas yet allowing TEXT modification within those areas I just described.

Does that help?

Thanks
onlyinamerica:beerchug:

fumei
08-05-2006, 01:37 AM
Yes.

I am gonna repeat myself.
When they are done filling in the information on the userform they click 'ok'. I then take the data they just entered and put that data into the empty textbox they just double clicked hence updating the document.Look at that. The user double clicks a textbox...fills out a userform...which puts that text in the textbox they just clicked....and they can still change anyway! You do NOT control what is in that textbox. The user can happily change it by putting the cursor in it (single click) and type away. From the POV of data, the userform is an EXTRA step, and I still think it is pointless.

1. The user can put that in the textbox anyway, without the userform step.

2. If you want the user to have access to the area, then there is nothing you can do about it.

I am a big fan of userforms. I like the idea of getting the information by way of a userform. I will repeat it again. Why use the textboxes???????????

Have the userform open on document open, or better, put a icon on the toolbar that shows the userform. Get the information via the userform, and put it into the document...no textboxes. Protect that section. Have the userform_intialize Sub unprotect, get the information, put that information into the document, then protect it again. The user will ONLY be able to change the data via the userform. If you keep the userform System Modal then will not be able to alter the protected section.
In a nutshell, how do you prevent the user from deleting, changing, editing a specific table, reference, textbox, footer, header, section while still allowing them total functionality within Word for all other areas yet allowing TEXT modification within those areas I just described.

You can't. Except by what I just said. The userform puts the text into those areas. The areas are protected. Edits are NOT allowed, but the user CAN call up the userform and modifies TEXT information, which is put back into the areas. Again, no need for textboxes.

There is no way to lock up an area for deleting, change shapes etc etc, but allow text changes. If you allow the user direct text modification in those areas...then the user gets the whole shebang for those areas. The only way IS to lock the area, but fill it from a userform, which of course you CAN control.

And....sigh...again, that is why using the ActiveX control textboxes is fine...except the user will always be able to delete and modify them.

onlyinameric
08-09-2006, 08:49 AM
Gerry,

you seem to be thoroughly exhausted with this.

you state: You do NOT control what is in that textbox. The user can happily change it by putting the cursor in it (single click) and type away.

not entirely true. if you lock the textbox they must enter the design mode to do this. they don't just click it and type away. what they can do immediately is highlight it and delete it but that removes links for the userform. if you could lock them out of the design mode then all they can do is delete it. if I could prevent them from deleting it and lock them out of the design mode then I would have achieved my goal.

But let say I remove the textboxes as you have so assuredly stated and I protect and unprotect the document. How do I allow them to draw shapes in other areas of the document? maybe I can't. I have stated many times that I want them to have free reign of all controls except in the areas the userform controls. That is probably the most important part because protecting the document limits the users capability of creating a nice procedure since they can't use the drawing package, modify page layout for printing, etc.

I think I know where I stand. Thanks.

onlyinameric
08-09-2006, 11:02 AM
oh, I also wanted to have them just double click the area or cells to pull up the userform. This will be distributed to many users so putting up an icon is more complicating for them. If I pull up the userform only when they open it up then they have to close it and open it again to make a change.

I don't know about you but I don't feel that's very clean.

lucas
08-09-2006, 02:19 PM
Why not just use a menu item. It is document specific(does not affect other doc files) look next to Help on the main menu to the right of file, etc. see attachment

lucas
08-09-2006, 02:22 PM
I would also like to suggest that Gerry is very knowledgeable on Word and VBA. If he suggests that you are going in the wrong direction then I would ask for a push in the right direction from him.

fumei
08-09-2006, 07:09 PM
Sorry, but the only way to get near what you are asking - which if I may, is simply - how to stop users from getting into Design Mode? - is to rewrite the DesignMode command.

if you could lock them out of the design mode then all they can do is delete it.This is incorrect. You are locking the control...they CAN'T delete it unless they get Design Mode. With Lock = True they can not select it.

To lock them out of calling Design Mode, put something like this in a code module.Sub ToggleFormsDesign()
If Environ("UserName") <> "gerry" Then
MsgBox "Design Mode is not available."
Else
ActiveDocument.ToggleFormsDesign
End If
End SubThis checks for the system logon name (me), and if it is NOT me displays a message that design Mode is not available. Design Mode will not toggle. If it IS me, obviously I want to do whatever I want.

However, of course anyone who wanted to can just go into the VBE and change this, or delete it. Then you are faced with locking them out of the VBE (possible) but it goes on and on. A good VBA person would get pass this. But it may work for you.
I have stated many times that I want them to have free reign of all controls except in the areas the userform controls.Do you have this backwards?You DO want them to put stuff into the userform controls, but you DON'T want them to have access to the ActiveX controls in the document. Right?

BTW: how are you moving the text from the userform controls to the ActiveX controls? Something like?Private Sub CommandButton1_Click()
ActiveDocument.InlineShapes(1).OLEFormat.Object.Text = _
TextBox1.Text
Unload Me
End SubOr have you explicitly named the ActiveX controls?

onlyinameric
08-10-2006, 05:46 AM
Lucas, I mean in no way to offend Gerry or his expertise. This isn't very easy to explain so it takes many iterations to make it clear. I haven't seen anyone try to do this on any forum so it's not easily explained.

I like the menu button but it doesn't get me to where I need to be. I sure could use a transporter right about now as you'd see what I mean.

Gerry, you're on the right track. I really like the userid check. I'll have to use that one. Very true I will have to lock them out of VBE. If the user is very good at VBE he can break the password or anything I put out there. It's those people that like to change formats of documents to suit their needs I want to control. And, you're right, this can go on and on as I'm finding.

I'm moving text from the userform to the renamed activeX controls like this:
With ActiveDocument
.PREPAREDBYBOX.Text = USERFORM1.PREPAREDBYBOX.Value
end with

I do the opposite to pull in any information they may have had in the document from a previous session into the userform.

Progress:
I had to head off the built in word macro functions to prevent the user from going into design mode. I did it a bit different than you have it but will use your idea of the userid to control when it's true or false.

Sub ViewControlToolbox()
CommandBars("Control toolbox").Visible = False
End Sub

When the user tries to go into design mode they can't. That solves the one problem. By locking the text boxes and turning off design mode they can now only place text onto the worksheet first page via the userform.

The next issue was that the user can still delete the text boxes and then type in information into the table. I, again, headed off the word macros by:

Sub EditClear()
Y = Selection.Range.Start
If Y < 1484 Then Exit Sub
X = Selection.Information(wdActiveEndAdjustedPageNumber)
If X = 1 Then Exit Sub
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub

This will work since I have a 'set in place' first page and therefore the character range will not change since they are modifying a textbox and not typing in text. (haven't confirmed but think that's correct) The x=1 the statement prevents any deletion on the first page if their selection is entirely on the first page. I did a fixed range in case their selection spanned beyond the first page. I think there's a better way. Idea? (X and Y are temporary values for now)

I did this same thing for 'cutting' the textboxes but now find that they can simply select the textboxes and hit 'backspace' or any other key to wipe them out. Remember, I can't do any protection as it limits too many formatting options.

I'm getting there. thanks for being patient.:friends:

fumei
08-11-2006, 06:29 PM
Bleeeech. Yuck. I don't like it.

Let's see if I have this correct. You are rewriting EditClear to check if the user has selected anything with a Range.Start of < the Long of the end of the first poage. You are going the hard code that value? Generally speaking, I would say that is poor programming....except you are absolutely correct. Text going into a textbox, an ActiveX textbox does not increase the Long of the page end.

OK - I have to say that is clever. And you refill the userform from existing values in the textboxes. Good.

An interesting issue. I have been playing with this a bit. I don't know. Locking users from functionality by rewriting commands...shrug, OK, maybe.

BTW: ToggleFormsDesigns does prevent the user from selecting the control (if the Lock prperty is True). However, if the selection INCLUDES the control, a delete will work.

If I understand correctly, you have control on other pages. Yes? If so, what are you going to do about preventing the user from deleting those?

I have to say that if your users are that destructive that you have the need for so much preventive coding...if they were my users I would try to train them. If they continued to be that destructive then they would have to accept the consequences.

onlyinameric
08-14-2006, 05:31 AM
yes! you now understand my situation. sorry it was so hard to get across. I agree, hardcoding that number and the way I'm controlling this is NOT good programming practice at all BUT I see no other way to do this. If I could enable the drawing toolbar once the document is protected then that would help.

As far as me protecting the other fields on the other sheets that's still outstanding. They are footers and headers and the users don't really care to modify that. They just have links/references/page numbers to the first page information area. They can't do much there even if they wanted. I could not allow them to enter into the footer/header area at all. That would probably do it. How? Well, maybe just prevent usage of the command completely by heading them off at the pass....maybe.

The users aren't really destructive, they just prefer the looks and functionallity of the document to be to their liking. Once they make the changes I won't ever see that document until it's too late.

Now that you grasp my concept/challenges:think: do you have any other ideas?

Thanks loads!
Regards,
Dan

fumei
08-14-2006, 02:41 PM
....why is the document NOT set up to their liking?

onlyinameric
08-15-2006, 05:44 AM
So you're saying you can satisfy 40 engineers with the same template, font, font size, color, spacing? maybe that should be another forum! :yes

lucas
08-15-2006, 06:28 AM
I hope I'm not reading sarcasm here.

So you're saying you can satisfy 40 engineers with the same template
Isn't that what standardization is by definition?

fumei
08-15-2006, 07:15 AM
Agreed. A standard template IS a good thing. especially as the OP is bending over backwards to make what CAN be flexible, flexible. He is requiring the functionality of the drawing toolbar (and other functionality) be available so the users can do what they want.

Now I do have issue with equating the users deleting things (like the textboxes) and the users changing format (font etc. etc.)

Which brings me back to why is the document not set up to their liking. WHY would a user delete one of the textboxes?

It is a constant give and take. The developer of a document template must create a document that serves the purposes of the users of it. On the other hand, users often want document structure to be, or act, in a way that is not appropriate for good documentation.

"Good" documentation is of course an immense subject and wildly debatable. However, there IS serious and considered research into technical writing. There ARE valid structures and format that make effective technical documents.

Within that context, yes, I agree with making documents tight with some restrictions on user changes. But it needs to in consultation with the users so that the document - as much as possible - fits their needs, and they won't want to make changes.

If there are users who insist on f&^$ing it up, then that is a different issue.

onlyinameric
08-15-2006, 07:16 AM
no sarcasm meant. I just know you can't satisfy all people all the time especially an engineer. Being one of them I know this is the case. Noone else ever has the best idea. That's the great thing about engineering is that if there's not a better way, there's a different way.

It is standardized. it's simply the formatting they like to play with. That's all.

onlyinameric
08-15-2006, 07:22 AM
I completely agree with both of you. who can argue with that? Not I.

I'm trying to prevent ANY meddling within the template. do I need to? no because they will lose functionality of the document. But, as you well know, debugging and prevention sometimes takes just as long or longer than the writing of the code. I can leave it as is and call it a day but I choose not to. :whip The tighter I can make it the better off I'll be.

lucas
08-15-2006, 07:47 AM
I don't understand why you need to give engineers the ability to draw in your word document:


How do I allow them to draw shapes in other areas of the document?

Word is a word processor....they surely have cad or equiv for their sketches......with much more control over the sketches.

onlyinameric
08-15-2006, 08:03 AM
lucas,

I want to provide this feature as it is highly helpful when adding pictures, drawing arrows, callouts, etc. Yes, you can use another program but you lose the ability to CLEANLY modify the document. The reasons behind me wanting to provide it, to me, is a moot point.

fumei
08-15-2006, 09:13 AM
No, there is no question in my mind that debugging and prevention DOES take longer than writing the code.

A lot of people focus way too much on the coding. Well designed processes, and considered logic often make the coding part, well not trivial, but far less of a problem that it would be otherwise.

I have to say though if your goal is to prevent ANY meddling...you will fail. This is simply not possible. You can make it a chore, which hopefully will take care of the vast majority of meddlers. Granted though, the tighter the better is not a bad thing.

So.....where are you with this???

fumei
08-15-2006, 09:29 AM
Darn, posts can fly way too fast....


Yes, you can use another program but you lose the ability to CLEANLY modify the document.Excuse me while I fall down into hysterical fits of laughter.....

IMHO, using Word's graphical abilities (the drawing toolbar) is NEVER a clean modification of a document. If I had my way, I would remove all graphical ability from Word. I mean other than being able to import graphics. Working with graphics, or worse yet creating them in Word is a joke.

If I need graphics, callouts etc. etc. etc. I do them in a proper graphic application, then bring them in. I hate the drawing toolbar.

onlyinameric
08-15-2006, 10:09 AM
hardy har har. :rotlaugh: That's not what I meant. Word is not a drawing program by any means true. It's very good for callouts, arrows, shapes, etc for a quick 'pointer' to locations referring from text. So if I say "install screw with washer" I can simply draw and arrow with a textbox rather than opening up the drawing in another program and working it that way. Also, we've had it where you no longer want arrows and circles pointing to a certain location changed and the picture is a hard picture with no mods available...such as in paint. That's a pain cuz the drawing is no longer valid. That means you have to retake the picture and do it again or go back into archives to find the original picture. anyway, that's off the topic. No wait I think I'm supposed to say "I hope I don't sense any sarcasm", right? :whistle:

Progress has halted for this week. other items on the plate as you know BUT I will keep posts.

lucas
08-15-2006, 10:17 AM
Glad to see you've maintained your sense of humor. Your points are well taken but as Gerry has pointed out it is virtually impossible to control everything a user might try to change. You can get it as clean as possible though. Best of luck

onlyinameric
08-15-2006, 10:20 AM
If there's one thing I hope to have for the rest of my life it's my sense of humor.:bug: :p :rofl: :rotlaugh: :eek:

Impossible?????? Now now. Improbable maybe. Impossible, no.

Thanks.:beerchug:

fumei
08-15-2006, 10:40 AM
Do let us know where this goes. In particular I am curious as to what you will do with the other objects.