brent.fraser
12-06-2012, 10:33 AM
Hi,
I am working on a form that has checkboxed and I would like to update a bookmark based on the checkmark. I have looked at the following piece and it seems to do part of the trick but it's pretty complicated:
http://www.vbaexpress.com/forum/showthread.php?t=40569&highlight=change+bookmark+text+based+on+checkbox
Basically, it's for an evaluation form with 5 categories (checkboxes) to choose from. If the user checks the "unsatisfactory" checkbox, I would like to change the "custSat" bookmark to "unsatisfactory." When the checkbox is not selected, the bookmark is blank.
This is what I have pieced together so far (that's semi working):
Sub ShowHide()
Dim BmkNm As String, NewTxt As String, BmkRng As Range, FFld As FormField
BmkNm = "MyBkMrk"
NewTxt = "Unsatisfactory-dude"
Good = "We Be Good"
Application.ScreenUpdating = False
With ActiveDocument
If .Bookmarks.Exists(BmkNm) Then
.Unprotect
Set BmkRng = .Bookmarks(BmkNm).Range
If .FormFields("Check1").Result = 0 Then
UpdateBookmark "MyBkMrk", NewTxt
UpdateAllRefFields
ElseIf BmkRng.Text <> "" Then
.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End
End If
'this part isn't working
If .FormFields("Check1").Result = 1 Then
UpdateBookmark "MyBkMrk", Good
UpdateAllRefFields
End If
.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End If
End With
Application.ScreenUpdating = True
End Sub
Also, should I use the legacy checkboxes or the new Content Controls? I haven't used them before and I am not sure how it changes the VBA stuff.
Tanks everyone.....
B
I am working on a form that has checkboxed and I would like to update a bookmark based on the checkmark. I have looked at the following piece and it seems to do part of the trick but it's pretty complicated:
http://www.vbaexpress.com/forum/showthread.php?t=40569&highlight=change+bookmark+text+based+on+checkbox
Basically, it's for an evaluation form with 5 categories (checkboxes) to choose from. If the user checks the "unsatisfactory" checkbox, I would like to change the "custSat" bookmark to "unsatisfactory." When the checkbox is not selected, the bookmark is blank.
This is what I have pieced together so far (that's semi working):
Sub ShowHide()
Dim BmkNm As String, NewTxt As String, BmkRng As Range, FFld As FormField
BmkNm = "MyBkMrk"
NewTxt = "Unsatisfactory-dude"
Good = "We Be Good"
Application.ScreenUpdating = False
With ActiveDocument
If .Bookmarks.Exists(BmkNm) Then
.Unprotect
Set BmkRng = .Bookmarks(BmkNm).Range
If .FormFields("Check1").Result = 0 Then
UpdateBookmark "MyBkMrk", NewTxt
UpdateAllRefFields
ElseIf BmkRng.Text <> "" Then
.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End
End If
'this part isn't working
If .FormFields("Check1").Result = 1 Then
UpdateBookmark "MyBkMrk", Good
UpdateAllRefFields
End If
.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End If
End With
Application.ScreenUpdating = True
End Sub
Also, should I use the legacy checkboxes or the new Content Controls? I haven't used them before and I am not sure how it changes the VBA stuff.
Tanks everyone.....
B