PDA

View Full Version : Password protect content control



limdul
01-21-2016, 11:05 AM
So this is going to be different. I am looking to have either a dropdown combo content control with multiple different names in them. If any of the names are picked I want to have a box to come up and ask for a password that was created by the user with the name. So for example if I had Bob, Jim, and Joe in the drop down box I would like to have each one have a different password attached to each name created by that person. Is there a way to do that? Or is there a way that if I have someone fill in the signature line on my form that it will ask for their password so that way other people cannot type any name in there. Hopefully that makes sense.

gmaxey
01-21-2016, 07:31 PM
This sort of thing would be a walk in the sun if the dimwits at Microsoft would fix the Word Object modules so that it where accessible while in the Content Control content store events. In the meantime you can use the registry:

You will need to map your "dropdown" content control to an XML part. Put the following code in the ThisDocument module. Run the setup to store the passwords.


Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
Select Case Content
Case "Bob"
If Not GetSetting("Demo", "Passwords", "BobPW") = InputBox("What is your password") Then
Content = vbNullString
End If
Case "Jim"
If Not GetSetting("Demo", "Passwords", "JimPW") = InputBox("What is your password") Then
Content = vbNullString
End If
Case "Joe"
If Not GetSetting("Demo", "Passwords", "JoePW") = InputBox("What is your password") Then
Content = vbNullString
End If
End Select
lbl_Exit:
Exit Sub
End Sub

Sub Setup()
SaveSetting "Demo", "Passwords", "BobPW", "12345"
SaveSetting "Demo", "Passwords", "JimPW", "54321"
SaveSetting "Demo", "Passwords", "JoePW", "12321"
lbl_Exit:
Exit Sub
End Sub

limdul
01-22-2016, 12:01 PM
Ah ok well I have never worked with XML before. Thank you for the code. I will have to use it later after I figure out how to work with XML and map the content control dropdowns to it. Thank you for the help.