Default value for checkbox

G

Guest

I have written a visual basic macro in word which opens a Form to allow the
user to enter data.

This form contains a check box with the default value set to True (ie
checkbox ticked)

Is it possible to chage the default value for this checkbox to False using a
macro.

Any help apperciated

Mike
 
J

Jay Freedman

cartman101 said:
I have written a visual basic macro in word which opens a Form to
allow the user to enter data.

This form contains a check box with the default value set to True (ie
checkbox ticked)

Is it possible to chage the default value for this checkbox to False
using a macro.

Any help apperciated

Mike

Hi Mike,

The answer depends on what kind of form contains the checkbox and what kind
of checkbox it is. There are at least three different ones. The strange part
is that you must have done something to change the default value to True,
because every one of these has a default value of False when it's first
created -- can you remember doing anything like this?

If the form is a Userform (a custom dialog created in the VBA editor), you
can use the Properties pane in the editor to set the Value property to
False, or you can use code like this to set the value in the
Userform_Initialize or Userform_Activate procedure:
Private Sub UserForm_Initialize()
CheckBox1.Value = False
End Sub

If the form is in the body of a document or template, did you create the
checkbox from the Forms toolbar or from the Control Toolbox?

- If it's from the Forms toolbar, open its Properties dialog and click the
"Not checked" radio button.

- If it's from the Control Toolbox, open its Properties dialog and change
its Value property to False. Like the Userform case, you can set the Value
in code, but here it would go in the Document_New procedure (see
http://word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm).
 
G

Guest

Thanks for the responce Jay.

The form is a UserForm created in VBA. The initial value is set at True,
using the properties box when the UserForm was created.

However on running a certain Macro I need the default seting to be changed
to False. Changing the value with the command
Address.CheckBox1=False
Changes the value, but when the file is saved and reopened the checkbox
reverts to the orriginal state (ie True)

Further assistance would be appreciated.

Mike
 
J

Jay Freedman

Hi Mike,

Are you using the same Userform for different kinds of documents, displaying
it from different macros? I don't quite follow how you know which default
should be used.

In any case, the macro that displays the Userform can set the default value
with something like this, assuming Address is the name of the Userform:

Public Sub ShowAddress()
Dim dlg As Address
Set dlg = New Address
dlg.CheckBox1.Value = False
dlg.Show
Set dlg = Nothing
End Sub

Another macro could show the same Userform but with the checkbox defaulting
to True simply by changing the assignment.

If you want the checkbox to keep whatever value the user selected and
display that value again after saving and reopening the document, you'll
have to provide code in the Userform (in the OK button's Click event and in
the Userform_Activate event) to save the value and restore it. The best way
is probably to store it as a document variable,
ActiveDocument.Variables("CheckBox1Val") = CheckBox1.Value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top