Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-03-2015, 02:52 PM
Eduardo Care Eduardo Care is offline Check box form field automatically checked Windows 8 Check box form field automatically checked Office 2010 64bit
Advanced Beginner
Check box form field automatically checked
 
Join Date: Aug 2015
Location: Cali
Posts: 32
Eduardo Care is on a distinguished road
Default Check box form field automatically checked

I read some tutorials for check boxes, so i realize its possible to work with them in different ways, like adding a macro to a group of check boxes so only 1 can be checked at the time.



What i trying to do its adding a check box that gets activated automatically when i check another box myself, if it its possible, adding a single check box that gets activated when at least one of another 2 check boxes are checked or both.

Is this possible? if it is please bring me your help, masters of word.

I don't know if this its a simple task but i didn't get done myself after a lot of time of research


Thanks in advance.

Last edited by Charles Kenyon; 09-06-2015 at 05:38 PM. Reason: Mark as solved
Reply With Quote
  #2  
Old 09-03-2015, 05:37 PM
Guessed's Avatar
Guessed Guessed is online now Check box form field automatically checked Windows 7 32bit Check box form field automatically checked Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Are you using Form Fields or Content Controls?

You will need to use a macro to control the logic but the coding will be pretty straightforward.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 09-03-2015, 09:48 PM
Eduardo Care Eduardo Care is offline Check box form field automatically checked Windows 8 Check box form field automatically checked Office 2010 64bit
Advanced Beginner
Check box form field automatically checked
 
Join Date: Aug 2015
Location: Cali
Posts: 32
Eduardo Care is on a distinguished road
Default

Im using Form fields.
Reply With Quote
  #4  
Old 09-03-2015, 11:07 PM
Guessed's Avatar
Guessed Guessed is online now Check box form field automatically checked Windows 7 32bit Check box form field automatically checked Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Assuming you have three checkboxes to test your code might work along these lines
Code:
Sub SetCheck()
  Dim bChecked As Boolean
  bChecked = False
  With ActiveDocument
    If .FormFields("Check1").CheckBox.Value Then bChecked = True
    If .FormFields("Check2").CheckBox.Value Then bChecked = True
    If .FormFields("Check3").CheckBox.Value Then bChecked = True
    .FormFields("Check4").CheckBox.Value = bChecked
  End With
End Sub
Assign the macro to run on exit for each of the formfields that trigger the summary checkbox.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 09-04-2015, 02:01 PM
Eduardo Care Eduardo Care is offline Check box form field automatically checked Windows 8 Check box form field automatically checked Office 2010 64bit
Advanced Beginner
Check box form field automatically checked
 
Join Date: Aug 2015
Location: Cali
Posts: 32
Eduardo Care is on a distinguished road
Default

Thanks for the code Guessed, but i should have been more specific, ill add a document with the checkboxes, and the other macro im using

Im already using another macro in my first 2 checkboxes, all i want its mark the "PV" box when any of the "Yes" boxes in my document its checked, i dont know if the macro it already has dont let me use your macro properly.


I need both of the macros, one to prevent both "yes" and "no" box to be checked and the other one to automatically check the "PV" box
Code:
Option Explicit

Sub ExclusiveCheckBoxes()
Dim strTemp As String
Dim oFF As FormField
Dim strGrpID As String
Dim strSeqID As String
Dim i As Long
Dim strSeqNext As String
  strTemp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 'Permits up to 26 checkboxes per group
  Set oFF = Selection.FormFields(1)
  If oFF.CheckBox.Value = True Then
    strGrpID = Left(oFF.Name, 8)
    strSeqID = UCase(Right(oFF.Name, 1))
  If strSeqID Like "[A-Z]" Then
    'Clear all GroupID ChkBoxes including the CB selected (ensure only one CB in group is selected).
    For i = 1 To Len(strTemp)
      strSeqNext = strGrpID & "_" & Mid(strTemp, i, 1)
      If ActiveDocument.Bookmarks.Exists(strSeqNext) Then
        ActiveDocument.FormFields(strSeqNext).CheckBox.Value = False
      End If
    Next i
    'Set the CB that was selected
    oFF.CheckBox.Value = True
    End If
  End If
lbl_Exit:
  Exit Sub
End Sub
Sub SetCheck()
  Dim bChecked As Boolean
  bChecked = False
  With ActiveDocument
    If .FormFields("CHK_1234_A").CheckBox.Value Then bChecked = True
    If .FormFields("CHK_2345_A").CheckBox.Value Then bChecked = True
    If .FormFields("Check1").CheckBox.Value Then bChecked = True
    .FormFields("Check1").CheckBox.Value = bChecked
  End With
End Sub
Attached Files
File Type: docm Risk Score.docm (22.3 KB, 9 views)
Reply With Quote
  #6  
Old 09-04-2015, 05:35 PM
Guessed's Avatar
Guessed Guessed is online now Check box form field automatically checked Windows 7 32bit Check box form field automatically checked Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can have them both running easily enough.
Code:
Option Explicit

Sub ExclusiveCheckBoxes()
Dim strTemp As String
Dim oFF As FormField
Dim strGrpID As String
Dim strSeqID As String
Dim i As Long
Dim strSeqNext As String
  strTemp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 'Permits up to 26 checkboxes per group
  Set oFF = Selection.FormFields(1)
  If oFF.CheckBox.Value = True Then
    strGrpID = Left(oFF.Name, 8)
    strSeqID = UCase(Right(oFF.Name, 1))
  If strSeqID Like "[A-Z]" Then
    'Clear all GroupID ChkBoxes including the CB selected (ensure only one CB in group is selected).
    For i = 1 To Len(strTemp)
      strSeqNext = strGrpID & "_" & Mid(strTemp, i, 1)
      If ActiveDocument.Bookmarks.Exists(strSeqNext) Then
        ActiveDocument.FormFields(strSeqNext).CheckBox.Value = False
      End If
    Next i
    'Set the CB that was selected
    oFF.CheckBox.Value = True
    End If
  End If
  SetCheck
lbl_Exit:
  Exit Sub
End Sub
Sub SetCheck()
  Dim bChecked As Boolean
  bChecked = False
  With ActiveDocument
    If .FormFields("CHK_1234_A").CheckBox.Value Then bChecked = True
    If .FormFields("CHK_2345_A").CheckBox.Value Then bChecked = True
    If Not .FormFields("Check1").CheckBox.Value Then
      .FormFields("Check1").CheckBox.Value = bChecked
    End If
  End With
End Sub
You can avoid the need for code to set exclusivity if you use option form controls with a group setting. This is a different look to the box with an x in it though so perhaps you intentionally did it that way.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 09-04-2015, 06:09 PM
Charles Kenyon Charles Kenyon is offline Check box form field automatically checked Windows 8 Check box form field automatically checked Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,138
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You might want to look at Greg Maxey's page.
Add Interactive Toggle Objects to Simple Word Documents
Reply With Quote
  #8  
Old 09-06-2015, 05:05 PM
Eduardo Care Eduardo Care is offline Check box form field automatically checked Windows 8 Check box form field automatically checked Office 2010 64bit
Advanced Beginner
Check box form field automatically checked
 
Join Date: Aug 2015
Location: Cali
Posts: 32
Eduardo Care is on a distinguished road
Default

First of all, i apologize for taking so long in reply to your both answers, thanks alot for the help.

Working just perfect by the way c:
Reply With Quote
  #9  
Old 09-07-2015, 03:31 PM
Eduardo Care Eduardo Care is offline Check box form field automatically checked Windows 8 Check box form field automatically checked Office 2010 64bit
Advanced Beginner
Check box form field automatically checked
 
Join Date: Aug 2015
Location: Cali
Posts: 32
Eduardo Care is on a distinguished road
Default

Hello people

I was tempted to ask for help, since i end up trying to create some conditions a little more specific but after many hours of researching and reading i learned to catch my own fish thanks to you all people c:

I was able to create the following code:

Code:
Option Explicit
Sub ExclusiveCheckBoxes()
Dim strTemp As String
Dim oFF As FormField
Dim strGrpID As String
Dim strSeqID As String
Dim i As Long
Dim strSeqNext As String
  strTemp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  Set oFF = Selection.FormFields(1)
  If oFF.CheckBox.Value = True Then
    strGrpID = Left(oFF.Name, 8)
    strSeqID = UCase(Right(oFF.Name, 1))
  If strSeqID Like "[A-Z]" Then
    'Clear all GroupID ChkBoxes including the CB selected (ensure only one CB in group is selected).
    For i = 1 To Len(strTemp)
      strSeqNext = strGrpID & "_" & Mid(strTemp, i, 1)
      If ActiveDocument.Bookmarks.Exists(strSeqNext) Then
        ActiveDocument.FormFields(strSeqNext).CheckBox.Value = False
      End If
    Next i
    'Set the CB that was selected
    oFF.CheckBox.Value = True
    End If
  End If
  SetCheck
lbl_Exit:
  Exit Sub
End Sub
Sub SetCheck()
  Dim bChecked As Boolean
  bChecked = False
  With ActiveDocument
    If .FormFields("CHK_1234_A").CheckBox.Value Or .FormFields("CHK_2345_A").CheckBox.Value Then .FormFields("PVresult").CheckBox.Value = True Else .FormFields("PVresult").CheckBox.Value = False
    If Not .FormFields("PVresult").CheckBox.Value Then
      .FormFields("PVresult").CheckBox.Value = bChecked
    End If
  End With
End Sub

Which allow me to have the following conditions:

If at least 1 of the 2 "Yes" Checkbox its market, mark PV box, if no "Yes" box its checked, PV box will be unchecked aswell.

If both "No" Boxes are checked, PV box will be unckecked too.

Only one box per group can be marked, so you cant have "Yes" and "No" box maked on the same Line.


Love you all ppl <3, any tip you guys think that could be useful go ahead, thanks alot for the help.
Attached Files
File Type: docm test.docm (23.4 KB, 15 views)
Reply With Quote
Reply

Tags
check boxes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Box Form Field Book Mark Auto Fill? zacam87 Word VBA 5 08-20-2014 02:56 PM
how to show total of check boxes checked worder Word 16 03-10-2014 05:07 PM
Check box form field automatically checked Repeat Spell check in a doc that has already been checked mawigfie Word 1 08-22-2012 01:16 PM
Check box form field automatically checked Word Macro That Checks a Check Box Form Field When File Print is Executed DKerne Word VBA 4 06-09-2011 11:54 AM
Form field to automatically be added to header? razberri Word VBA 3 02-22-2010 03:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:11 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft