PDA

View Full Version : Solved: Use a Userform Checkbox to Change State of Corresponding Document Checkbox



em.
07-14-2008, 02:03 AM
Hello all,

I?m pretty new to vba so any suggestions/samples would be great. I have a userform created for a fax template that pops up when the template is opened, ready for user entry.

There are three checkboxes on the userform that allow the user to select if the fax is urgent, for review, or for your information.

In the document, I have added checkboxes to match the above three choices (I used the active x controls to do this and named them the same name as the userform checkboxes)

If a user ticks the urgent checkbox in the userform, the checkbox in the document should update to show this choice when the user clicks on the OK button on the userform. I have not been able to find a solution to this though I?m sure it is quite simple.

Many thanks in advance J

lucas
07-14-2008, 10:56 AM
This is an easy to understand method since you only have 3 checkboxes.

me.checkbox is on the userform and Doccheckboxes are on the document.

Option Explicit
Private Sub CommandButton1_Click()
If Me.CheckBox1.Value = True Then ThisDocument.DocCheckBox1.Value = True
If Me.CheckBox1.Value = False Then ThisDocument.DocCheckBox1.Value = False
If Me.CheckBox2.Value = True Then ThisDocument.DocCheckBox2.Value = True
If Me.CheckBox2.Value = False Then ThisDocument.DocCheckBox2.Value = False
If Me.CheckBox3.Value = True Then ThisDocument.DocCheckBox3.Value = True
If Me.CheckBox3.Value = False Then ThisDocument.DocCheckBox3.Value = False
End Sub


Look for the menu item next to help to run the userform.

fumei
07-14-2008, 01:35 PM
If they are just matching anyway (True on one = True on the other; False on one = False on the other), why bother testing with an IF? Just make them equal.


ThisDocument.DocCheckBox1.Value = Me.CheckBox1.Value
ThisDocument.DocCheckBox2.Value = Me.CheckBox2.Value
ThisDocument.DocCheckBox3.Value = Me.CheckBox3.Value

They will match no matter what the value is, True or False.

lucas
07-14-2008, 03:27 PM
Good cleanup Gerry. thanks.

em.
07-14-2008, 03:43 PM
That is fantastic! I thought it might be a simple process. Works great, many thanks for all your help fumei and lucas :)
em.

lucas
07-14-2008, 08:09 PM
em, please mark your thread solved using the thread tools at the top of the page.

em.
07-17-2008, 11:32 PM
Sorry about that :) thanks for your help