Consulting

Results 1 to 10 of 10

Thread: Solved: Yes/No Checkboxes Complete Before E-mail?

  1. #1
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location

    Solved: Yes/No Checkboxes Complete Before E-mail?

    That is a rather confusing title I think so I apologise and will explain. I wish to ensure that, prior to e-mailing a form to a distribution list, that all questions have been answered by clicking either a Yes or No Checkbox. If details are required, I also want to ensure that those details are given. Can anyone start me on my way with this with some ideas or code? I have set up a simple IF formula to return TRUE if neither relevant checkbox is ticked. Am I on the right road with this or is there a better way? I would like an error message to pop up if the answer for any of these options is TRUE that says something like "Please go back and fully complete the form prior to sending"

    Any thoughts?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Derek
    That is a rather confusing title I think so I apologise and will explain. I wish to ensure that, prior to e-mailing a form to a distribution list, that all questions have been answered by clicking either a Yes or No Checkbox. If details are required, I also want to ensure that those details are given. Can anyone start me on my way with this with some ideas or code? I have set up a simple IF formula to return TRUE if neither relevant checkbox is ticked. Am I on the right road with this or is there a better way? I would like an error message to pop up if the answer for any of these options is TRUE that says something like "Please go back and fully complete the form prior to sending"

    Any thoughts?
    Derek,

    What sort of checkboxes do you have. How are they set up (linked?)

    What technology do you use to send the email.

    What have you already got?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location
    I have tried to attach a sample file which will answer all your questions but it seems I am only aloowed one file at a time, and I have a file attached to a thread called "ComboBox query". The checkboxes are linked to cells, so that I can see a text Yes or No. All our machines use Outlook and I already have the e-mail working fine. I just need the warning/error message prior to creation of the e-mail.

    As I said previously, I have used a simple IF formula to check if both cells say nothing, returning a true/false answer. My thoughts were that there could be some code to check the text in these cells and if any say TRUE then an error message could pop up stating that the form is incomplete, and that the user must go back and complete.

    Any help is most appreciated

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Derek
    I have tried to attach a sample file which will answer all your questions but it seems I am only aloowed one file at a time, and I have a file attached to a thread called "ComboBox query". The checkboxes are linked to cells, so that I can see a text Yes or No. All our machines use Outlook and I already have the e-mail working fine. I just need the warning/error message prior to creation of the e-mail.

    As I said previously, I have used a simple IF formula to check if both cells say nothing, returning a true/false answer. My thoughts were that there could be some code to check the text in these cells and if any say TRUE then an error message could pop up stating that the form is incomplete, and that the user must go back and complete.

    Any help is most appreciated
    I would check the checkboxes directly in the code

    [vba]
    If Not ActiveSheet.CheckBoxes("Check Box 1") = 1 Or _
    Not ActiveSheet.CheckBoxes("Check Box 2") = 1 Then
    MsgBox "incomplete"
    Else
    'do the Outlook stuff
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location
    When I use that code I get an error message which says:

    Run-time error '1004'
    Unable to get the checkboxes property of the worksheet class

    I have played with the Check Box 1 name to CheckBox1 etc and changed the value from 1 to 0 but still get the same error.

    Thoughts?

  6. #6
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location
    Just a quick post to remind you all that I need some help.

  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Quote Originally Posted by Derek
    I have tried to attach a sample file which will answer all your questions but it seems I am only aloowed one file at a time, and I have a file attached to a thread called "ComboBox query".
    Hi Derek,

    I don't think that should matter. As long as you try to attach a zip file, it should work. I know that I have many concurrent files uploaded...
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try the following for the checkbox check
    [VBA]
    Sub AllFilled()
    For Each X In ActiveSheet.OLEObjects
    If X.ProgId = "Forms.CheckBox.1" Then
    If IsNull(X.Object.Value) Then
    MsgBox "Please fill all checkboxes"
    Exit Sub
    End If
    End If
    Next
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    I think the problem here is that not all the check boxes need to be checked... if fact half of them should be (provided they are all Yes/No)
    That being the case, you could just count them all, and count the number of checked ones to confirm all questions have been answered[VBA]Dim lngChkBoxCount As Long
    Dim lngChkBoxTickedCount As Long
    Dim ctrl As Object

    For Each ctrl In ActiveSheet.OLEObjects
    If TypeName(ctrl.Object) = "CheckBox" Then
    lngChkBoxCount = lngChkBoxCount + 1
    If ctrl.Object.Value Then
    lngChkBoxTickedCount = lngChkBoxTickedCount + 1
    End If
    End If
    Next ctrl

    If Not lngChkBoxTickedCount = lngChkBoxCount / 2 Then
    MsgBox "Please complete all questions"
    Else
    'send workbook
    End If[/VBA]One issue here is that some bright spark could check yes and no in one question and nothing in another and the test would still pass.
    This is why you should be using OptionButtons and setting the GroupName property the same for each Yes/No pair so that for each question, only one answer can be given.
    You could still use this code, just change the TypeName test from "CheckBox" to "OptionButton".
    K :-)

  10. #10
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location
    Thanks to everyone who has helped with this little problem. Using your feedback AND my original idea, I got this to work rather nicely.

    What I did was to craete a simple little IF formula/function to return TRUE if neither relevant boxes were ticked. then simple VBA code saying if TRUE returned "Go Back and Fix!" message popped up.

    Thank you all for your input. It once again was invaluable in coming up with the solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •