Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2022, 09:57 PM
Guessed's Avatar
Guessed Guessed is offline Make a field required Windows 10 Make a field required Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default


Your code can temporarily change the CC to make it editable and then change it back after it is edited.
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean)
  Dim aDate As Date, ccDue As ContentControl
  If aCC.ShowingPlaceholderText Then
    Select Case aCC.Tag
      Case "Rev. #", "PDR #", "Date of Discovery", "Type"   'these CCs require an answer
        MsgBox "This Content Control requires a response.", vbInformation + vbOKOnly, "INPUT REQUIRED"
        Cancel = True
    End Select
  Else    'if CC has content, check its type matches the content
    If aCC.Tag Like "*[#]" Then     'if the CCs tag ends with '#'
      If Not IsNumeric(aCC.Range.Text) Then
        MsgBox "This field requires a numeric response.", vbInformation + vbOKOnly, "INPUT REQUIRED"
        Cancel = True
      End If
    ElseIf aCC.Tag Like "*Date*" Then   'if CCs tag includes 'Date'
      If Not IsDate(aCC.Range.Text) Then
        MsgBox "This field requires a date response.", vbInformation + vbOKOnly, "INPUT REQUIRED"
        Cancel = True
      ElseIf aCC.Title = "Date of Initiation" Then    'note tag doesn't match on this CC in your doc
        aDate = CDate(aCC.Range.Text) + 30
        Set ccDue = ActiveDocument.SelectContentControlsByTitle("Due Date")(1)
        ccDue.LockContents = False
        ccDue.Range.Text = Format(aDate, "d mmm yyyy")    'if date picker, format may be as per CC property
        ccDue.LockContents = True
      End If
    End If
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Make a field required how to make a template with field and mailmerge to work together in protected mode pjkon Mail Merge 1 06-10-2019 04:35 PM
How To Make 2013 Populate To Field abraxis Outlook 2 08-10-2018 06:41 AM
Make a field required How to make a Check Box Form Field red if not checked? CarlCR Word Tables 3 07-12-2016 08:35 PM
Make a field required How to make a SEQ field show up in cross references? Roscoe Word 5 06-01-2016 01:39 PM
make text form field active dependent on dropdown Glenn0004 Word VBA 1 06-23-2015 06:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft