PDA

View Full Version : Fill a protected form using Bookmarks



zopita
07-26-2010, 02:40 AM
Hello,

I need to make a protected form with a list of 100 items numbered from 1 to 100 (item 1, item 2, item 3...), and a table with 2 column .

In the column 1 I have some text fields.

When the user fill a textfield with a number, in the second column must appears the item: if he types "3" in the first column in the second column must appears "item 3", and so one.

I was tried to make it wiht bookmarks but the macro doesn't work.

Thanks for your help.

fumei
07-26-2010, 08:37 AM
It is protected for forms because you want to use text formfields?

"I was tried to make it wiht bookmarks but the macro doesn't work."

To use bookmarks you will have to unprotect the document.

What happens if they type "3 "? Three and a space.
What happens if they type " 3"? Spave and a three.
What happens if they type "blah"?

What is - if any - the relationship of the list to the table formfields?

You have the list of 100 tems...and listed how? This is just plain text?

gmaxey
07-26-2010, 02:13 PM
zopita,

I know that you tried to use the JustAnswer service on my website to ask this question but those clowns have not figured out how to ensure that questions directed to me using that link are not mis-categorized by their moderators into a category that I am restricted from answering. They classified your question for a "Computer Programmer" expert even though the link indicates you asked a Word Expert question. If you get the opportunity to give them some feedback please tell them about the stupidity of their system.

Gerry asked good questions of course and you will need to give those some thought.

Lets say that your users will be accruately enter 1, 2, 3 .... 100 in the text fields in column 1. You will need a standard naming convention for the 100 text fields (lets use Row1, Row2, Row3 ... Row100) and you will need to run an OnExit macro from each field. When the macro runs it needs to determine the row number and the value entered by the user. Using that data you can then put practically anything in column 2. The function shown is just one way to define that data. Good luck.

Sub OnExit()
Dim i As Long
i = Selection.Information(wdEndOfRangeRowNumber)
Select Case Val(ActiveDocument.FormFields("Row" & i).Result)
Case 1 To 100
ActiveDocument.Unprotect
ActiveDocument.Tables(1).Cell(i, 2).Range.Text = GetItem(ActiveDocument.FormFields("Row" & i).Result)
ActiveDocument.Protect wdAllowOnlyFormFields, True
Case Else
MsgBox "Oops, you did not follow the simple instructions."
End Select
End Sub
Function GetItem(ByRef Item As String) As String
Select Case Item
Case 1
GetItem = "This is the item 1 description"
Case 2
GetItem = "This is the item 2 description"
'Etc, Etc.
End Select
End Function

fumei
07-26-2010, 02:42 PM
Very nice Greg.

zopita
07-27-2010, 06:13 AM
It is protected for forms because you want to use text formfields?
Yes. The user only can to write in this fields.

You say me: “To use bookmarks you will have to unprotect the document.”
I now. No problem using ActiveDocument.Protect/Unprotect
If the user types a bad entry like "3 ", a warning message box appears: “Only numbers, no spaces”

Relationship of the list to the table formfields:

Imagine the list of 7 days of week (plain text):
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
.................

In the first column of the table there are some formfields and the user has to type a number from 1 to 7.
If he types 3, in the second column appears Wednesday, if he types 1 in the second column appears Monday.....

Gerry, I hope I explained a little better. Greg wrote in his post the solution JustAnswer gave me. It works!

Thanks for your patience. Gloria

zopita
07-27-2010, 06:26 AM
Hi Greg,

You'll find my message in 90% of internet forums dedicated to Visual Basic. I was desperate.

Please write what I have to say to JustAnswer. Clowns do not, right? xD Then I copy / paste.

Greetings. Gloria

fumei
07-27-2010, 10:36 AM
"If the user types a bad entry like "3 ", a warning message box appears: “Only numbers, no spaces”

And do you have the error trapping code to do this?

gmaxey
07-27-2010, 12:25 PM
zopita,

I was able get one of the moderators at JustAnswers to redesignate your question to a category where I could answer. The answer you got there was the one I posted there, here, and several other places.

You would probably be wasting your time to give JA any feedback. I have been trying for over a year to get them to stop redirecting questions that originate from my site into different categories.

I hope you will accept the JA answer so I will get the pauper's share of the proceeds. Thanks.

zopita
07-29-2010, 12:02 AM
Hi, Gerry,
I put text fields with the property "numeric" so that only supports numbers. I have made many tests and seems to be sufficient for my needs. Or do you have any suggestions for me? Thanks!
Sincerely,
Gloria

zopita
07-29-2010, 12:06 AM
Hi Greg,
The macro works very well. I changed two lines of code because I have to password protect the form. It's perfect for my needs.

A detail. If the user makes a wrong entry (letters instead of numbers) warning window appears and the cursor jumps to the next field. Is it possible to stay in the wrong field for the user to reenter the information?

One other thing I wanted to comment you (for me it's no problem): when there is in the table a row whith the first cell empty and text in the second cell (a title, for example) the macro does not work. If that text is in the first cell the macro works perfectly. If the two cells are combined into one also works.
I hope this feedback is useful for you.

Greetings,
Gloria

gmaxey
07-29-2010, 03:53 AM
Gloria,

You would need to set a revised OnExit and an OnEntry macro to each formfield. The purpose is to determine the field identity OnEntry and then if there is an issue OnExit to execute code to reenter the offending field. This all happens so quickly to be transparent to a user. Example code is shown here:

http://www.gmayor.com/formfieldmacros.htm

zopita
07-30-2010, 12:27 AM
Greg, your site is very nice. Thanks!

Regards,
Gloria