Skip to main content
Participating Frequently
August 12, 2020
Question

Force Entry in Text Field and Unprotect Template

  • August 12, 2020
  • 1 reply
  • 926 views

I’m creating a template in Word 2016, and I have a couple of issues. Most of the fields have an on entry macro associated with them to force text input for the prior field. A message box comes up if the user tabs out of the field without inputting text.

My first issue is this: The last field, E-mail, has an on entry macro for the field before it, Extension, and an on exit macro so if the user tabs out of the E-mail field a message box comes up.

When the user completes the Extension field and tabs to the E-mail field, if they tab out of the field without entering text a message box comes up letting the user know they need to enter text into that field. However, when the user clicks the OK button the cursor advances to the first input field (Dropdown1). I would like it to stay on the Extension field, Text 13. Below is my coding:

 

Sub ForceEmail()

Dim Msg, Style, Title, Response

On Error GoTo fError

If ActiveDocument.FormFields("Text13").Result = "" Then

   Msg = "You must enter text in the E-mail field."

   Style = vbOKOnly + vbCritical

   Title = "Input Text Warning"

   Response = MsgBox(Msg, Style, Title)

   Selection.GoTo wdGoToBookmark, Name:="Text13"

End If

Exit Sub

fError:

   MsgBox Err.Description

End Sub

 

My second issue is when the user has entered text into the E-mail field and they tab out of it, I need the template to unprotect and delete the header of the template. The coding below is what I have been using as an on exit macro on many templates and it has worked before, but now I am thinking I need to add the below coding to the ForceEmail coding since I have placed that as an on exit macro in the E-mail field. I have tried adding the coding below to the coding above but cannot get it to work.

 

Sub DocUnPro()

'If document is protected, unprotect it.

   If ActiveDocument.ProtectionType <> wdNoProtection Then

       ActiveDocument.Unprotect Password:=""

   End If

   With ActiveDocument.Sections(1)

       .Headers(wdHeaderFooterPrimary).Range.Text = ""

   End With

   ActiveDocument.Bookmarks("Dropdown1").Select

End Sub

 

Any help you can give me on these two issues is greatly appreciated. Jamie

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
August 12, 2020

So what does this have to do with Acrobat?

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Jamie5EA9Author
Participating Frequently
August 12, 2020

Oh my gosh Thom, you're right, wrong platform. My apologies.