I have checkbox controls embedded (InlineShape) in a word document.
Depending on values in these and other controls, sections of the document gets deleted.
My problem is, is that once sections are deleted, then the controls embedded in those sections no longer exist, so I can't use the control names in the VBA, I get compiler errors when other subs/function run...
I currently have a function that works fine, and locates the control by it's name.
[code:vb]
Function FindCheck(ByVal pName As String) As CheckBox
Dim oCheck As CheckBox
Dim oILS As InlineShape
' return is Nothing if strName is not found
Set oCheck = Nothing
' look through the InlineShapes collection for
' one that is an OLEControl with the proper name
For Each oILS In ActiveDocument.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If LCase(oILS.OLEFormat.Object.Name) = LCase(pName) Then
Set oCheck = oILS.OLEFormat.Object
Exit For
End If
End If
Next
Set FindCheck = oCheck
End Function
[/code]
[code:vb]
Set oCheckBox = FindCheck("chkC51")
If Not oCheckBox Is Nothing Then
If oCheckBox.Value = False Then
[color:red]oCheckBox.Enabled = False[/color]
End If
End If
[/code]
This works fine with the equivalent ComboBox function. But for some reason with CheckBox object the Enabled property goes missing.
Any ideas as to how I get around this?
Depending on values in these and other controls, sections of the document gets deleted.
My problem is, is that once sections are deleted, then the controls embedded in those sections no longer exist, so I can't use the control names in the VBA, I get compiler errors when other subs/function run...
I currently have a function that works fine, and locates the control by it's name.
[code:vb]
Function FindCheck(ByVal pName As String) As CheckBox
Dim oCheck As CheckBox
Dim oILS As InlineShape
' return is Nothing if strName is not found
Set oCheck = Nothing
' look through the InlineShapes collection for
' one that is an OLEControl with the proper name
For Each oILS In ActiveDocument.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If LCase(oILS.OLEFormat.Object.Name) = LCase(pName) Then
Set oCheck = oILS.OLEFormat.Object
Exit For
End If
End If
Next
Set FindCheck = oCheck
End Function
[/code]
[code:vb]
Set oCheckBox = FindCheck("chkC51")
If Not oCheckBox Is Nothing Then
If oCheckBox.Value = False Then
[color:red]oCheckBox.Enabled = False[/color]
End If
End If
[/code]
This works fine with the equivalent ComboBox function. But for some reason with CheckBox object the Enabled property goes missing.
Any ideas as to how I get around this?