G
gouved
I copied a procedure from an article cited in this discussion group on how to
assign values to a field. The routine is:
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Set aDoc = ActiveDocument
Dim BMRange As Range
BMRange.Text = CStr(TextToUse)
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
If aDoc.ProtectionType <> wdNoProtection Then
aDoc.Unprotect
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
aDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword
Else
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
aDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword
End If
I then wrote code to translate a checkbox as either true or false and call
the procedure above to set the value of the field accordingly:
Sub SetIfBenefitBox()
'
' SetIfBenefitBox Macro
' Macro created 12/1/2008 by Edgar Velazquez
'
Dim StrVal As String
With ActiveDocument
If .FormFields("IfBenefit").CheckBox.Value = True Then
MsgBox ("chkbox is checked")
StrVal = True
Else
MsgBox ("chkbox is not checked")
StrVal = False
End If
UpdateBookmark "Benefit", CStr(StrVal)
End With
End Sub
When I pass the checkbox, the checkbox macro sends the msgbox, but on
calling the subroutine, I get the VB Runtime Error 91, with the editor
identifying the problem on assigning the BMRange.text for:
BMRange.Text = TextToUse
and: BMRange.Text = CStr(TextToUse)
Can anyone please help?
assign values to a field. The routine is:
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Set aDoc = ActiveDocument
Dim BMRange As Range
BMRange.Text = CStr(TextToUse)
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
If aDoc.ProtectionType <> wdNoProtection Then
aDoc.Unprotect
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
aDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword
Else
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
aDoc.Protect Type:=wdAllowOnlyRevisions, Password:=strPassword
End If
I then wrote code to translate a checkbox as either true or false and call
the procedure above to set the value of the field accordingly:
Sub SetIfBenefitBox()
'
' SetIfBenefitBox Macro
' Macro created 12/1/2008 by Edgar Velazquez
'
Dim StrVal As String
With ActiveDocument
If .FormFields("IfBenefit").CheckBox.Value = True Then
MsgBox ("chkbox is checked")
StrVal = True
Else
MsgBox ("chkbox is not checked")
StrVal = False
End If
UpdateBookmark "Benefit", CStr(StrVal)
End With
End Sub
When I pass the checkbox, the checkbox macro sends the msgbox, but on
calling the subroutine, I get the VB Runtime Error 91, with the editor
identifying the problem on assigning the BMRange.text for:
BMRange.Text = TextToUse
and: BMRange.Text = CStr(TextToUse)
Can anyone please help?