Set ActiveDocument Variable

P

Patrick C. Simonds

I am trying to put together some code which would run the line below, only
if CheckBox1 through CheckBox15 were false.

ActiveDocument.Variables("Disability").Value = "Incomplete"










---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000755-0, 07/09/2007
Tested on: 7/10/2007 11:27:26 AM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com
 
R

Russ

Patrick,

One way to do it.
Try this long If statement. Of course fill in the ellipsis with the other
checkbox numbers using Or between them all.

With WhateverParentObjectIs
If Not .CheckBox1.Value Or .... Or .CheckBox15.Value then
ActiveDocument.Variables("Disability").Value = "Incomplete"
End If
End With
 
O

old man

Hi,

You can try this:

Sub checkall()
Dim i1 As Integer
Dim good1 As Boolean

good1 = True

For i1 = 1 To 15
If Me.FormFields("Checkbox" & Trim(i1)).Result = False Then
good1 = False
Exit For
End If
Next

If good1 = False Then
ActiveDocument.Variables("Disability").Value = "Incomplete"
End If


End Sub
 
P

Patrick C. Simonds

I get a "Method data member not found" error. Just to add a little more
info the CheckBoxes (1-15) are located on the open UserForm, which is
UserForm6. and this code will be part of the code attached to a "Finished:
button on the UserForm.


old man said:
Hi,

You can try this:

Sub checkall()
Dim i1 As Integer
Dim good1 As Boolean

good1 = True

For i1 = 1 To 15
If Me.FormFields("Checkbox" & Trim(i1)).Result = False Then
good1 = False
Exit For
End If
Next

If good1 = False Then
ActiveDocument.Variables("Disability").Value = "Incomplete"
End If


End Sub





---
avast! Antivirus: Inbound message clean.
Virus Database (VPS): 000755-0, 07/09/2007
Tested on: 7/10/2007 2:40:14 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com




---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000755-0, 07/09/2007
Tested on: 7/10/2007 3:03:50 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com
 
P

Patrick C. Simonds

I should have mentioned that the "Method data member not found" error was
caused by "Me.FormFields"

Patrick C. Simonds said:
I get a "Method data member not found" error. Just to add a little more
info the CheckBoxes (1-15) are located on the open UserForm, which is
UserForm6. and this code will be part of the code attached to a "Finished:
button on the UserForm.







---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000755-0, 07/09/2007
Tested on: 7/10/2007 3:03:50 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com





---
avast! Antivirus: Inbound message clean.
Virus Database (VPS): 000755-0, 07/09/2007
Tested on: 7/10/2007 3:31:00 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com




---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000755-0, 07/09/2007
Tested on: 7/10/2007 3:41:20 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com
 
J

Jay Freedman

Userforms don't contain a FormFields collection, they contain a
Controls collection. The line should be

If Me.Controls("Checkbox" & Trim(i1)).Result = False Then

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
P

Patrick C. Simonds

Well sort of. Here is what I did (does it need to be it's own routine?)


Private Sub CommandButton2_Click()

Dim i1 As Integer
Dim good1 As Boolean

good1 = True

For i1 = 1 To 15

If Me.Controls("Checkbox" & Trim(i1)).Result = False Then

good1 = False
Exit For
End If
Next

If good1 = False Then
ActiveDocument.Variables("Disability").Value = "Incomplete"
End If

End Sub








old man said:
Hi,

Did you put the subroutine checkall in the code attached to your form?

old man




---
avast! Antivirus: Inbound message clean.
Virus Database (VPS): 000755-0, 07/09/2007
Tested on: 7/10/2007 5:52:56 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com




---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000755-0, 07/09/2007
Tested on: 7/10/2007 5:59:26 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com
 
O

old man

Hi,

The code I wrote was for fields added to a document body not to a form If
you have created a user form named (default name userform1) then this would
work:

For i1 = 1 To 15
'check the next line !!!
If UserForm1.Controls("checkbox" & Trim(i1)) = False Then
good1 = False
Exit For
End If
Next


Old Man
 
P

Patrick C. Simonds

OK here is the code to date, but it does not matter if one of the 15
CheckBoxes on UserForm6 is checked or not. It always returns a False (I
added the MsgBox temporaly, so I could see how the variable was being set)



Private Sub CommandButton2_Click()

Dim i1 As Integer
Dim good1 As Boolean

good1 = True

For i1 = 1 To 15
'check the next line !!!
If UserForm6.Controls("checkbox" & Trim(i1)) = False Then
good1 = False
Exit For
End If

Next

If good1 = False Then
ActiveDocument.Variables("Disability").Value = "Incomplete"

End If

MsgBox ActiveDocument.Variables("Disability").Value

End Sub




---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000755-1, 07/11/2007
Tested on: 7/10/2007 9:24:05 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com
 
P

Patrick C. Simonds

Upon further investigation I have found it works if all 15 CheckBoxes are
checked (true), I want it to return False only when none of the 15
CheckBoxes are checked.

Patrick C. Simonds said:
OK here is the code to date, but it does not matter if one of the 15
CheckBoxes on UserForm6 is checked or not. It always returns a False (I
added the MsgBox temporaly, so I could see how the variable was being set)



Private Sub CommandButton2_Click()

Dim i1 As Integer
Dim good1 As Boolean

good1 = True

For i1 = 1 To 15
'check the next line !!!
If UserForm6.Controls("checkbox" & Trim(i1)) = False Then
good1 = False
Exit For
End If

Next

If good1 = False Then
ActiveDocument.Variables("Disability").Value = "Incomplete"

End If

MsgBox ActiveDocument.Variables("Disability").Value

End Sub



---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000755-1, 07/11/2007
Tested on: 7/10/2007 9:24:05 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com





---
avast! Antivirus: Inbound message clean.
Virus Database (VPS): 000755-1, 07/11/2007
Tested on: 7/10/2007 9:59:33 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com




---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000755-1, 07/11/2007
Tested on: 7/10/2007 10:11:38 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com
 
R

Russ

Patrick,
Here's what I suggested in my first reply:

With UserForm1
If Not .CheckBox1.Value Or .CheckBox2.Value Or _
.CheckBox3.Value Or .CheckBox4.Value Or _
.CheckBox5.Value Or .CheckBox6.Value Or _
.CheckBox7.Value Or .CheckBox8.Value Or _
.CheckBox9.Value Or .CheckBox10.Value Or _
.CheckBox11.Value Or .CheckBox12.Value Or _
.CheckBox13.Value Or .CheckBox14.Value Or _
.CheckBox15.Value Then
ActiveDocument.Variables("Disability").Value = "Incomplete"
End If
End With
 
R

Russ

Patrick,
Patrick,
Here's what I suggested in my first reply:

With UserForm1 With UserForm6 'in your case
If Not .CheckBox1.Value Or .CheckBox2.Value Or _
.CheckBox3.Value Or .CheckBox4.Value Or _
.CheckBox5.Value Or .CheckBox6.Value Or _
.CheckBox7.Value Or .CheckBox8.Value Or _
.CheckBox9.Value Or .CheckBox10.Value Or _
.CheckBox11.Value Or .CheckBox12.Value Or _
.CheckBox13.Value Or .CheckBox14.Value Or _
.CheckBox15.Value Then
ActiveDocument.Variables("Disability").Value = "Incomplete"
End If
End With
 
R

Russ

Patrick,
Borrowing from others the code for the loop, here's another way

Dim good1 As Boolean
Dim i1 As Integer
good1 = False
For i1 = 1 To 15
good1 = good1 Or UserForm6.Controls("checkbox" & Trim(i1)).Value
Next i1
If Not good1 Then
ActiveDocument.Variables("Disability").Value = "Incomplete"
End If
 

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

Similar Threads

Spell check a TextBox 2
Multipage UserForm 3
Saving a document 3
Calendar output 1
Document save question 2
outlook 2003 inbox 2
phatom message in Outlook 2003 1
How do you hide ..... 2

Top