Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox control in Word

Status
Not open for further replies.

JA3395

Programmer
May 22, 2007
88
IE
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?
 


Hi,

Perhaps, rather than CheckBoxes, you use a ComboBox. When a Section gets deleted, you ALSO delete from the ComboBox ListFillRange, so the control ALWAYS reflects that remains in the document.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I've ended up using the InlineShape object. I did have a big example here, but my connection keeps collapsing and I only get seconds to send things....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top