Results 1 to 8 of 8
  1. #1
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71

    Question Verify that all toggles are switched before completing

    Greetings,

    I have a script I found on the 'net that verifies that all the toggle buttons on a form have been pressed. If not then a message pops up. However, while I understand what it's doing, I'm not sure how it's doing it. I was hoping that someone here could explain the syntax and what things are calling/refering to. My code is below.

    Code:
    Private Sub Command16_Click()
        Dim ctl As Control
        
        For Each ctl In Controls
            If ctl.ControlType = acToggleButton Then
                If ctl.Name <> "Toggle1" Then
                    If ctl.Value = 0 Then
                        MsgBox "Not all areas have been checked."
                        ctl.SetFocus
                        Exit Sub
                    End If
                End If
            End If
        Next
    End Sub
    I understand that it's checking the status of each control that's a togglebutton, but I don't get what the second if statement, If ctl.Name <> "Toggle1" Then, is really doing.



    I know I should be happy I found something that works, but without knowing how it's working I won't be able to modify it to fit my application. Or, rather, I'm afraid to modify it for fear of totally messing it up.

    If someone could either point me to a resource on the 'net I could use, or explain the script, I would be very grateful.

    Thanks,

    DD

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    It's ignoring the control named Toggle1 - every other togglebutton will be verified except that one.

    And, I must congratulate you on your desire to understand how and why the code is working. You'll get a lot farther in life with that attitude, and you'll leave less land mines lying around for people to stumble into - including yourself in "people".

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    That line is exempting a toggle with that name from the test. In essence, all toggles except "Toggle1" must be pressed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    Okay, so it's looking for all toggles except for 'Toggle1'. In essence it's looking at all the toggles because there is no 'toggle1'? If I had a toggle called 'toggle1' it wouldn't check that, correct.

    So what that if statement is really for is to set it up so that it's looking for something that doesn't exist, which forces the script to check all of the toggles until it runs out of toggle controls to check.

    What about the ctl.setfocus - why is that being set as the focus?

    Thanks Dal and pbaldy for the info.

    DD

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    When it finds a control that does not meet the criteria, it sets focus on that control. Hopefully this helps the user understand which control needs attention

  6. #6
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    Okay, cool.. I didn't even notice it was doing that on my test bed.

    Last question: What would be the best vba reference source for someone diving into vba scripting? I'd like something that not only explains not only the basics, but give some examples or some higher end stuff - like this checkbox check script. Or how to nest if statments, or boolean expressions. Basically something that tells what vba is, the commands and how to do some intricate scripting - including modules.

    If there is more than one source I should be looking for that's fine.

    Thanks all for the help and clarity. It's much appreciated.

    DD

  7. #7
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Start with post #5 in this thread https://www.accessforums.net/access/...ess-38592.html

  8. #8
    dcdimon's Avatar
    dcdimon is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Bradenton, FL
    Posts
    71
    Thanks for the pointers.

    DD

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Completing Table updates
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 04-10-2013, 11:51 PM
  2. Auto completing data entry forms
    By adamlukegilbert in forum Forms
    Replies: 1
    Last Post: 09-06-2011, 08:58 AM
  3. Verify this Query
    By dongodu in forum Queries
    Replies: 1
    Last Post: 06-21-2011, 11:08 AM
  4. Verify This Error
    By dongodu in forum Queries
    Replies: 3
    Last Post: 05-30-2011, 07:19 AM
  5. Verify state field
    By pwmichaelsr in forum Access
    Replies: 5
    Last Post: 08-16-2010, 12:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums