El_muchacho
05-15-2016, 05:11 AM
Hello, i have another problem with my function.
This function is made to check if a checkbox is checked and to hide the associated text (placed in a bookmark) if i isn't.
In any case the checkbox (without the associated text) is hidden.
Here is the complete function
Private Sub CommandButton21_Click()With ActiveDocument
Dim intI As Integer
intI = 1
Dim Str As String
Str = "CaseACocher"
Dim Str2 As String
Dim Str3 As String
Dim fldCheck As FormField
Dim Compteur1 As Integer
Dim Compteur2 As Integer
For Each fldCheck In ActiveDocument.FormFields
If fldCheck.Type = wdFieldFormCheckBox Then
fldCheck.Range.Font.Hidden = True
Compteur1 = Compteur1 + 1
End If
Next fldCheck
For intI = 1 To Compteur1 Step 1
Str2 = Str & intI
If .FormFields(Str2).CheckBox.Value = False Then
.Bookmarks(Str2).Range.Font.Hidden = True
Else
End If
Next intI
.Protect wdAllowOnlyFormFields, noreset
End With
End Sub
The problem is in this loop
For intI = 1 To Compteur1 Step 1Str2 = Str & intI
If .FormFields(Str2).CheckBox.Value = False Then
.Bookmarks(Str2).Range.Font.Hidden = True
Else
End If
Next intI
The problem is that the whole function only runs if we have conitnuous variable name which are CaseACocher1 then CaseACocher2 then CaseACocher3 CaseACocher4 etc.
If i a user decides to change the Word document, to delete checkboxes, the loop will be stopped because a bookmark won't be find because i has been deleted.
For example if we have : bookmark1 then bookmark2 then bookmark4 the loop won't find bookmark3 and stop.
So can i add something to ignore if something doesn't exist ?
Or if there is something to directly get each bookmarks associated with the checkboxes (by default a bookmark is associated with a checkbox, if i use their name it must run), so i won't need a counter by just a "ForEachCheckbox.bookmark" (or something like that).
I hope it was clear enough.
Thanks
This function is made to check if a checkbox is checked and to hide the associated text (placed in a bookmark) if i isn't.
In any case the checkbox (without the associated text) is hidden.
Here is the complete function
Private Sub CommandButton21_Click()With ActiveDocument
Dim intI As Integer
intI = 1
Dim Str As String
Str = "CaseACocher"
Dim Str2 As String
Dim Str3 As String
Dim fldCheck As FormField
Dim Compteur1 As Integer
Dim Compteur2 As Integer
For Each fldCheck In ActiveDocument.FormFields
If fldCheck.Type = wdFieldFormCheckBox Then
fldCheck.Range.Font.Hidden = True
Compteur1 = Compteur1 + 1
End If
Next fldCheck
For intI = 1 To Compteur1 Step 1
Str2 = Str & intI
If .FormFields(Str2).CheckBox.Value = False Then
.Bookmarks(Str2).Range.Font.Hidden = True
Else
End If
Next intI
.Protect wdAllowOnlyFormFields, noreset
End With
End Sub
The problem is in this loop
For intI = 1 To Compteur1 Step 1Str2 = Str & intI
If .FormFields(Str2).CheckBox.Value = False Then
.Bookmarks(Str2).Range.Font.Hidden = True
Else
End If
Next intI
The problem is that the whole function only runs if we have conitnuous variable name which are CaseACocher1 then CaseACocher2 then CaseACocher3 CaseACocher4 etc.
If i a user decides to change the Word document, to delete checkboxes, the loop will be stopped because a bookmark won't be find because i has been deleted.
For example if we have : bookmark1 then bookmark2 then bookmark4 the loop won't find bookmark3 and stop.
So can i add something to ignore if something doesn't exist ?
Or if there is something to directly get each bookmarks associated with the checkboxes (by default a bookmark is associated with a checkbox, if i use their name it must run), so i won't need a counter by just a "ForEachCheckbox.bookmark" (or something like that).
I hope it was clear enough.
Thanks