D
Dylan
Error 5941 - The requested member of the collection does not exist.
I get this error trying to apply a calendar result to a bookmarked
formfield. The macro pauses and the following line is highlighted in yellow:
With rng.Bookmarks(1)
.Range.FormFields(1).Result = Format(ctrlCal.Value, "dd MMM yyyy")
Here is the full code I'm using:
Private Sub ctrlCal_Click() 'Calendar Control
Dim rng As Range
Dim bProtected As Boolean
Set rng = Selection.Range
'Unprotect
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
With rng.Bookmarks(1)
.Range.FormFields(1).Result = Format(ctrlCal.Value, "dd MMM yyyy")
End With
Unload Me
'.Range.FormFields("Text19").Select
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub
I get this error trying to apply a calendar result to a bookmarked
formfield. The macro pauses and the following line is highlighted in yellow:
With rng.Bookmarks(1)
.Range.FormFields(1).Result = Format(ctrlCal.Value, "dd MMM yyyy")
Here is the full code I'm using:
Private Sub ctrlCal_Click() 'Calendar Control
Dim rng As Range
Dim bProtected As Boolean
Set rng = Selection.Range
'Unprotect
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
With rng.Bookmarks(1)
.Range.FormFields(1).Result = Format(ctrlCal.Value, "dd MMM yyyy")
End With
Unload Me
'.Range.FormFields("Text19").Select
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub