VBA Code to allow more that 256 characters in Text Box Form Field

Hello,

In a protected document, I have a Text Box Form Field that may sometimes require more than 256 characters.

I have an On Exit macro that passes the contents of the first text box to a second text box.

My macro code is below:

------------------

Sub CopyIntake_Present_Prob()

    
    Dim Str1 As String
       
    Str1 = ActiveDocument.FormFields("Intake_Present_Prob").Result
    ActiveDocument.FormFields("Assess_Present_Prob").Result = Str1

End Sub

------------------

If the user of the form enters more than 256 characters, they receive  Run-time error '4609'

In researching a solution, I found some suggested code for resolving this error.  The code is as follows:

ActiveDocument.Unprotect
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Text = Str1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

I have tried including the code above in my original macro but have not been successful. 

If you agree that the above code is a viable solution, please advise how I should modify my original code to include the additional code.

If you do not agree that the above code is a viable solution, what would you suggest?

Thank you for your time.

Mark

Answer
Answer

Your exit macro should look like this:

Sub CopyIntake_Present_Prob()
    
    Dim Str1 As String
        
    Str1 = ActiveDocument.FormFields("Intake_Present_Prob").Result
    ActiveDocument.Unprotect
    ActiveDocument.Bookmarks("Assess_Present_Prob").Range.Fields(1).Result.Text = Str1
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub

_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 424 Applies to: