PDA

View Full Version : Restricting content control that is linked to a dropdown comboBox in Userform



jpabz
02-11-2016, 11:26 AM
Hello

is there a way to lock the content control that is linked to a combobox on a userform? Currently, users are able to go in the document and edit the controls. I can lock the control using content controls property, but the userform combobox linked to textbox that is then pasted to the document will not work due to being locked.

Code example

Private Sub Combobox3_Change()
If ComboBox3.Value = "Applied Research" Then
TextBox8.Value = "Dr. Bob"
TextBox20.Value = "Dr. James"
ElseIf ComboBox3.Value = "Corporate" Then
TextBox8.Value = "Dr. Jay"
TextBox20.Value = "Dr. Gray"
End If
End Sub


Private Sub CommandButton1_Click()
With ActiveDocument

.SelectContentControlsByTitle("Dr. Name").Item(1).Range.Text = Me.TextBox20
.SelectContentControlsByTitle("Alternate Doctor").Item(1).Range.Text = Me.ComboBox8

End Sub

gmaxey
02-11-2016, 01:44 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
With ActiveDocument.SelectContentControlsByTitle("Test").Item(1)
.LockContents = False
.Range.Text = "Whatever"
.LockContents = True
End With
lbl_Exit:
Exit Sub
End Sub

jpabz
02-11-2016, 03:32 PM
Hi Greg, thanks for the help, but I can't seem to make the code work.. what am I doing wrong? Thanks again!

Sub ScratchMacr()
With ActiveDocument.SelectContentControlsByTitle("Dr. Name").Item(1)
.LockContents = False
.Range.Text = "Dr. James"
.LockContents = True
End With
Exit Sub
End Sub

gmaxey
02-11-2016, 04:30 PM
Your macro works just fine here. Are you sure that your title is correct?

jpabz
02-11-2016, 04:39 PM
Yes, the title of the content control is "Dr. Name"...Whenever the I change the combo box in the user form it will then insert the text to the content control..that works, but when I go to the document i am still able to edit the control...

gmaxey
02-11-2016, 05:29 PM
You can't edit the contents of the control unless you go back to properties and uncheck the box "Contents cannot be edited."

We seem to be in Do...Loop here. What are you trying to do?

jpabz
02-12-2016, 10:31 AM
Greg, check your message box. I will send you an example file.

jpabz
02-12-2016, 10:37 AM
I have a user form that will transfer information to the document. Once a user clicks submit, I do not want them to edit the content control...but is able to change the content in the userform to make the changes..

See image exampole

15399

gmaxey
02-12-2016, 10:41 AM
I don't see a message or file from you anywhere? There is nothing that you can do to stop someone from clicking Developer>Controls>Properties and uncheck "Contents cannot be edited" other than setting editing restrictions.

jpabz
02-12-2016, 12:26 PM
so there's no way around this then eh....damm

gmaxey
02-13-2016, 06:25 AM
I'm not saying that. I still don't know what "this" is. What exactly are your trying to do? First you said that you didn't want the user to be able to edit the CC from the document then you groused about not be able to edit it from the document after the form closed. If you want to only edit it with the user from then show the form on entry, and get out of the CC when you close the Userform.