Thread: [Solved] Make a field required
View Single Post
 
Old 07-26-2022, 12:30 PM
CellCharger CellCharger is offline Windows 10 Office 2019
Novice
 
Join Date: Oct 2021
Location: NJ, USA
Posts: 24
CellCharger is on a distinguished road
Default

Thank you Andrew,

Please excuse my lack of knowledge.

I fixed the field tags but when I pasted the code below the existing code, I get the error message (see the attachment).

And just for the record, the the first code was from another post that I created.



this is the code

Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim Dt As Date, StrDt As String
With CCtrl
  If .Title <> "Date of Initiation" Then Exit Sub
  If .ShowingPlaceholderText = True Then
    ActiveDocument.SelectContentControlsByTitle("Due Date")(1).Range.Text = ""
  Else
    StrDt = .Range.Text
    If IsDate(StrDt) Then
      Dt = CDate(StrDt)
    Else
      Dt = CDate(Split(StrDt, (Split(StrDt, " ")(0)))(1))
    End If
    ActiveDocument.SelectContentControlsByTitle("Due Date")(1).Range.Text = Format(Dt + 30, .DateDisplayFormat)
  End If
End With
Application.ScreenUpdating = True
End Sub
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
  Select Case ContentControl.Tag
    Case "Rev. #"
      If ContentControl.ShowingPlaceholderText Then
        MsgBox "Rev. # requires a numeric response.", vbInformation + vbOKOnly, "INPUT REQUIRED"
        Cancel = True
      End If
    Case "PDR #"
      If ContentControl.ShowingPlaceholderText Then
        MsgBox "PDR # requires a numeric response.", vbInformation + vbOKOnly, "INPUT REQUIRED"
        Cancel = True
      End If
    Case "Date of Discovery"
      If ContentControl.ShowingPlaceholderText Then
        MsgBox "Date of Discovery requires a numeric response.", vbInformation + vbOKOnly, "INPUT REQUIRED"
        Cancel = True
      End If
    Case "Type"
      If ContentControl.ShowingPlaceholderText Then
        MsgBox "Type requires a numeric response.", vbInformation + vbOKOnly, "INPUT REQUIRED"
        Cancel = True
      End If
    Case "ManNum"
      If Not IsNumeric(ContentControl.Range.Text) Then
        MsgBox "This field requires a numeric response.", vbInformation + vbOKOnly, "INPUT REQUIRED"
        Cancel = True
      End If
  End Select
lbl_Exit:
  Exit Sub
End Sub
I attached the form just in case.
Attached Images
File Type: jpg Error.jpg (28.5 KB, 29 views)
Attached Files
File Type: docm Report Due Date (1) fixed.docm (56.5 KB, 10 views)

Last edited by CellCharger; 07-27-2022 at 05:49 AM.
Reply With Quote