Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Jul 2010
    Location
    London
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi all

    I would like a message to appear to make sure that when the user changes the value of a check box to true that that is what they intended to do.

    I am trying to use the code as follows

    Private Sub Paid_BeforeUpdate(Cancel As Integer)
    Dim intCont As Integer
    If Me.Paid = False Then
    intCont = MsgBox("Are you sure this invoice has been paid", vbYesNo)
    If intCont = vbYes Then
    Me.Paid = True
    Else
    Cancel = True
    End If
    End If


    End Sub

    It doesn't work? It would be great if somebody could tell me where i'm going wrong.

    Many thanks

    Amanda

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Code:
    Change code to use the click event as follows:
    
    Private Sub Paid_Click()
        Dim intCont As Integer
        If  Me.Paid  Then   '*** If checked the item is marked paid? ***
           If  MsgBox("Are you sure this invoice has been paid", vbYesNo) = vbNo then
                 Me.Paid = False
            End If
        End If
    
    
    End Sub
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Lounger
    Join Date
    Jun 2010
    Location
    Manchester, NH
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't recall there being a "Check" event. There is a "Click" however

    If you put that code in the Click event for the Paid checkbox, it should work. Unless I missed something, I don't think that you need the variable declaration though.


    Bob Oxford
    Bob Oxford
    Software Wizards, Inc.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    First of all, you should really get in the habit of renaming your controls so they don't have the same name as the control source. Using an accepted object prefix is a good way to do this. In your situation, I'd do this:

    Private chkPaid_BeforeUpdate(Cancel as Integer)
    If chkPaid=true then
    If vbno=MsgBox("Are you sure this invoice has been paid", vbYesNo) then
    Cancel=true
    chkpaid.undo
    end if
    end if
    end sub
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quote Originally Posted by Bob Oxford View Post
    I don't recall there being a "Check" event. There is a "Click" however

    Bob Oxford
    Bob, you're quite right it was my fat fingers...I meant to use Click! I updated the previous post to reflect that. Thanks for the catch.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    The advantage of using the 'before update" event as Mark Liquorman suggests is that it does not depend on the method used to set the value. The OnClick event only fires when the mouse is used, but it is possible to set the value of a checkbox using the keyboard (with the spacebar).
    Regards
    John



  7. #7
    New Lounger
    Join Date
    Jul 2010
    Location
    London
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all that information - I've learnt a lot.

    It is now working just as I wanted it so thanks very much and I have renamed the control as you suggested.

Posting Permissions

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