Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2011, 04:46 PM
Johnny thunder Johnny thunder is offline Check Box Macro Windows XP Check Box Macro Office 2003
Novice
Check Box Macro
 
Join Date: Apr 2011
Posts: 10
Johnny thunder is on a distinguished road
Default Check Box Macro

Hello Friends,

I am using a Form that was created thru MS Word and has several selection criteria in the form of check boxes. I want to add another check box that says select all.

I need a macro that will look to about 15 checkboxes that I have labeled "LMSI_1 - LMSI_15" and check the boxes once the macro runs.



Any ideas? I am using Office 2003. Thanks for any help provided!
Reply With Quote
  #2  
Old 04-05-2011, 06:28 PM
macropod's Avatar
macropod macropod is offline Check Box Macro Windows 7 32bit Check Box Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Johnny,

You could use an 'on exit' macro attached to the 'select all' checkbox, coded like:
Code:
Sub CheckAll()
Dim FrmFld As FormField, bChkAll As Boolean
With ActiveDocument
  bChkAll = .FormFields("CheckAll").Result
  For Each FrmFld In .FormFields
    If FrmFld.Type = wdFieldFormCheckBox Then FrmFld.Result = bChkAll
  Next
End With
End Sub
Note: The above code assumes your 'select all' checkbox has the bookmark name 'CheckAll' assigned to it. Checking the box checks all checkboxes; unchecking it unchecks them.

For something a little more sophisticated, you could use an 'on entry' macro as well to test the state of the checkbox before it is clicked, with code like the 'GetChkState' below:
Code:
Dim bChkAll As Boolean
 
Sub CheckAll()
Dim FrmFld As FormField
With ActiveDocument
  If .FormFields("CheckAll").Result = bChkAll Then Exit Sub
  bChkAll = .FormFields("CheckAll").Result
  For Each FrmFld In .FormFields
    If FrmFld.Type = wdFieldFormCheckBox Then FrmFld.Result = bChkAll
  Next
End With
End Sub
 
Sub GetChkState()
bChkAll = ActiveDocument.FormFields("CheckAll").Result
End Sub
With this approach, the checkboxes will only be updated if the checked state of the 'select all' checkbox has changed. This might help prevent some accidental updates. Note that the 'CheckAll' sub has been modified to suit and that the 'bChkAll' variable is now module-wide.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-06-2011, 10:28 AM
Johnny thunder Johnny thunder is offline Check Box Macro Windows XP Check Box Macro Office 2003
Novice
Check Box Macro
 
Join Date: Apr 2011
Posts: 10
Johnny thunder is on a distinguished road
Default

That worked out great!

I have another question, I have changed a few check Boxes to Form Fields with drop-down comments "Add" "Delete" and I was able to write the code that will mirror the comment from my Select all form field but I was only able to write it for one other individual bookmark, I have a range of form fields 1-15 labeled "LMSI_Office1 - LMSI_Office15" and I was not sure how to write that in code?

Sub CopyField()
Dim Temp As String
Temp = ActiveDocument.FormFields("LMSI_Office1").Result
ActiveDocument.FormFields("LMSI_Office2").Result = Temp
End Sub

Above is my code. I also need to add something to this and don't know how to do it, I need the code to un-protect the sheet before running the macro (No password required) and then re-protect the sheet "protect document for forms" Any idea's on the above question?

The range question would really help out cause manually writing in 15 lines seems like overkill?

Thanks for your help!
Reply With Quote
  #4  
Old 04-06-2011, 03:05 PM
macropod's Avatar
macropod macropod is offline Check Box Macro Windows 7 32bit Check Box Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Johnny,

Try:
Code:
Sub CopyField()
Dim StrResult As String, i As Integer
With ActiveDocument
  StrResult = .FormFields("LMSI_Office1").Result
  For i = 2 To 15
    .FormFields("LMSI_Office" & i).Result = StrResult
  Next
End With
End Sub
As for unprotecting/reprotecting the document, none of these macros I've posted needs that - they all run fine while the document is protected.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-07-2011, 09:46 AM
Johnny thunder Johnny thunder is offline Check Box Macro Windows XP Check Box Macro Office 2003
Novice
Check Box Macro
 
Join Date: Apr 2011
Posts: 10
Johnny thunder is on a distinguished road
Default

the macro worked out perfectly!!! Now how would I modify the code to say If I want to blank everything out again?

So my drop Down list has three criteria "Blank (empty form-field)" "Add", "Delete".
Reply With Quote
  #6  
Old 04-07-2011, 04:01 PM
macropod's Avatar
macropod macropod is offline Check Box Macro Windows 7 32bit Check Box Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Johnny,

Provided all the fields have the empty result option, you shouldn't need to change anything in the code - simply choose the empty result in the 'LMSI_Office1' formfield.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-07-2011, 04:08 PM
Johnny thunder Johnny thunder is offline Check Box Macro Windows XP Check Box Macro Office 2003
Novice
Check Box Macro
 
Join Date: Apr 2011
Posts: 10
Johnny thunder is on a distinguished road
Default

I tried it and the only way I can get it to work is if I pu the macro "On exit" and after selecting blank scroll down to the next form-field and then the macro executes?

I am sending this form to people who don't follow directions well so I want to make it as user friendly as possible.

Is there a way to put in the code after selecting blank the code will run the macro and then scroll down one form field?

In excel I use the code FoundCell.Offset(1,1) to move down one cell from where the current postition is. Doesnt work in Word?
Reply With Quote
  #8  
Old 04-07-2011, 04:21 PM
macropod's Avatar
macropod macropod is offline Check Box Macro Windows 7 32bit Check Box Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Johnny thunder View Post
I tried it and the only way I can get it to work is if I pu the macro "On exit" and after selecting blank scroll down to the next form-field and then the macro executes?
That's the way formfields work - anything you change in them doesn't take effect until you exit the formfield (eg by tabbing to or selecting the next formfield).
Quote:
Is there a way to put in the code after selecting blank the code will run the macro and then scroll down one form field?
Simply tabbing out of the formfield will do that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 04-07-2011, 04:29 PM
Johnny thunder Johnny thunder is offline Check Box Macro Windows XP Check Box Macro Office 2003
Novice
Check Box Macro
 
Join Date: Apr 2011
Posts: 10
Johnny thunder is on a distinguished road
Default

Quote:
Simply tabbing out of the formfield will do that.
So is there a way to code in a tab out to the code so it automatically does it.

What I am trying to accomplish is, if a user gets the formand only needs to select all once and then save the sheet and send it back to me I don't want to tell them after selecting the formfield use tab or scroll down with the keyboard, I want it to happen automatically.

And putting the macro "On entry" works but if the change the drop down to "Add" and then change there minds and put "delete" the macro doesnt run the second time. It just runs the "Add" all the way down? Do you know of any fixes? The way I was fixing it was unprotecting the sheet and then re-run the macro in VBA Editor but the user I send this too won't have access to unprotect? Im stuck...
Reply With Quote
  #10  
Old 04-07-2011, 04:39 PM
macropod's Avatar
macropod macropod is offline Check Box Macro Windows 7 32bit Check Box Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Johnny thunder View Post
So is there a way to code in a tab out to the code so it automatically does it.

What I am trying to accomplish is, if a user gets the formand only needs to select all once and then save the sheet and send it back to me I don't want to tell them after selecting the formfield use tab or scroll down with the keyboard, I want it to happen automatically.
Well, as I also said in my previous post:
Quote:
anything you change in them doesn't take effect until you exit the formfield
Quote:
Originally Posted by Johnny thunder View Post
And putting the macro "On entry" works but if the change the drop down to "Add" and then change there minds and put "delete" the macro doesnt run the second time. It just runs the "Add" all the way down? Do you know of any fixes? The way I was fixing it was unprotecting the sheet and then re-run the macro in VBA Editor but the user I send this too won't have access to unprotect? Im stuck...
If the user chooses "Add", then changes their mind before exiting the formfield, nothing else will have been updated, so selecting "Delete" or re-selecting "Blank" is what will take effect when the finally do exit the formfield. Obviously, though, if the user changes their mind after exiting the formfield, they'll have to re-do the input and redo the exit event before the 'on exit' macro can fire.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 04-07-2011, 04:42 PM
Johnny thunder Johnny thunder is offline Check Box Macro Windows XP Check Box Macro Office 2003
Novice
Check Box Macro
 
Join Date: Apr 2011
Posts: 10
Johnny thunder is on a distinguished road
Default

If I was to put the macro "On entry" once the macro runs if the user changes the drop down to another comment to have the macro re-run? I think maybe that was the question I should have asked.

When I do this now it seems like the macro will only run once?
Reply With Quote
  #12  
Old 04-07-2011, 04:46 PM
macropod's Avatar
macropod macropod is offline Check Box Macro Windows 7 32bit Check Box Macro Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Johnny thunder View Post
If I was to put the macro "On entry" once the macro runs if the user changes the drop down to another comment to have the macro re-run? I think maybe that was the question I should have asked.
No, that's not viable either. An 'On Entry' macro only runs when you enter the formfield, not while you're doing anything in it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 04-07-2011, 04:47 PM
Johnny thunder Johnny thunder is offline Check Box Macro Windows XP Check Box Macro Office 2003
Novice
Check Box Macro
 
Join Date: Apr 2011
Posts: 10
Johnny thunder is on a distinguished road
Default

I will try the method code you posted on the other post and see what I come up with.

Thanks again for all your help!
Reply With Quote
Reply

Tags
macro, vba, word 2003



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Box Macro check with condition karti Word 2 03-15-2011 06:06 AM
Check whether Follow Up set konfis Outlook 0 10-27-2010 11:19 PM
Need Help with Using a Check Box Nick9589 Excel 1 05-01-2010 09:29 AM
Spell Check WorkerB Word 2 11-21-2009 07:22 AM
Check Box in Word serayam Word 1 11-06-2008 06:45 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:01 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