Identiying whether the user is checking or unchecking a checkbox (1 Viewer)

w11184

Registered User.
Local time
Today, 20:09
Joined
Feb 20, 2012
Messages
41
I have a checkbox on my form that basically deletes a record when the user ticks the checkbox. What I want to know is how do i check whether the person is "ticking" or "unticking" a checkbox before any action is carried out?
 

pr2-eugin

Super Moderator
Local time
Today, 20:09
Joined
Nov 30, 2011
Messages
8,494
Use the AfterUpdate event of the Check box.
Code:
Private Sub checkBoxName_AfterUpdate()
    If Me.checkBoxName Then
        MsgBox "CheckBox is now Ticked"
    Else
        MsgBox "CheckBox is now Unticked"
    End If
End Sub
 

w11184

Registered User.
Local time
Today, 20:09
Joined
Feb 20, 2012
Messages
41
but what about if I want to confirm with the user whether they defintiely want to tick/untick it?
 

pr2-eugin

Super Moderator
Local time
Today, 20:09
Joined
Nov 30, 2011
Messages
8,494
Use the BeforeUpdate event instead of AfterUpdate.
Code:
Private Sub checkBoxName_BeforeUpdate(Cancel As Integer)
    If MsgBox("Are you sure you want to " & IIF(Me.checkBoxName = True, "Tick", "Untick") & " the checkbox?", vbYesNo) = vbNo Then
        Cancel = True
    End If
End Sub
 

Users who are viewing this thread

Top Bottom