PDA

View Full Version : Using ActiveX check boxes



Roderick
03-15-2011, 08:46 AM
I'm using Word 2007 in Vista Premium. I have a template with macros and the coding is password protected.

I want to use two ActiveX check boxes in the body of the document so that when the template is run and the new document is completed there is a pair of simple Yes/No checkboxes asking the user for some information. The default is the NO check box with its .Value set to True within its properties.

Both check boxes have the same group name set within each of their properties.

I've got the following code located within the ThisDocument Object in the VBE project:
==================================
Sub chkNo_Click()
With ThisDocument
If .chkNo Then
.chkYes = False
End If
End With
End Sub

Sub chkYes_Click()
With ThisDocument
If .chkYes Then
.chkNo = False
End If
End With
End Sub
=============================

When I run the template the check boxes do not respond to the commands to select each other checked or unchecked. They act completely independent of each other ignoring that the group name is the same.

Can anyone point me where I'm going wrong, please?

Thanks. Roderick

Paul_Hossler
03-15-2011, 04:17 PM
Checkboxes do operate indendently

Radio buttons do no



Option Explicit
Private Sub chkYes_Click()
chkNo.Value = Not chkYes.Value
End Sub
Private Sub chkNo_Click()
chkYes.Value = Not chkNo.Value
End Sub

Private Sub Document_Open()
chkYes.Value = True
End Sub


Paul

Roderick
03-15-2011, 04:52 PM
Thanks Paul for your guidance. I put all three procedures in the MyDocument Object in the VBE project and then run the template.

Reading your VBA coding it becomes blindingly obvious what it should be doing but one has to double click on each check box the first time the new document is created to "kickstart" them into life. Once that is done then they seem to work as designed.

There must be a reason for this odd behaviour but I'm stumped as to the reason why!

Roderick

fumei
03-16-2011, 09:55 AM
"the first time the new document is created "

Then use Document_New, not Document_Open.