Hi macropod,
Many thanks for the solution and getting back so quickly. There are two things that happen when I set the dates a second time. The message appears:
Run-time error '6124':
You are not allowed to edit this selection because it is protected.
Debug shows: Text = vbNullString
With ActiveDocument.CustomDocumentProperties
Str1 = Format(.Item("ToDt").Value, "MM YYYY")
Str2 = Format(.Item("FromDt").Value, "MM YYYY")
End With
MsgBox Str1 & vbTab & Str2
If Str1 = Str2 Then
Set RngTmp = .Range
With RngTmp
.Start = .Words.Last.Start - 1
.Text = vbNullString
End With
End If
.Type = wdContentControlDate
End With
End If
.Type = wdContentControlDate
End If
End With
Done:
Application.ScreenUpdating = True
End Sub
When I reset, the following line is highlighted:
ActiveDocument.CustomDocumentProperties("ToDt").Value = Format(ContentControl.Range.Text, "MM/DD/YYYY")
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim i As Long, j As String, Rng As Range, RngTmp As Range
Dim CCtrl As ContentControl, Str1 As String, Str2 As String
With ContentControl
If (.Title = "Visit Date - From") Or (.Title = "Visit Date - To") Then
If .Range.Text = .PlaceholderText Then Exit Sub
.Type = wdContentControlRichText
Set Rng = .Range
If .Title = "Visit Date - From" Then
ActiveDocument.CustomDocumentProperties("ToDt").Value = Format(ContentControl.Range.Text, "MM/DD/YYYY")
ElseIf .Title = "Visit Date - To" Then
ActiveDocument.CustomDocumentProperties("FromDt").Value = Format(ContentControl.Range.Text, "MM/DD/YYYY")
End If
For i = 0 To UBound(Split(.Range.Text, " "))
j = Split(.Range.Text, " ")(i)
After that I am unable to get the calendar to appear.
Also, is it possible for the code to run without the message boxes displaying. Many thanks.
Kind regards,
JDS_916