Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"cancel" the checking of a check box?

Status
Not open for further replies.

sohunter

Technical User
Dec 3, 2001
106
US
I want to give user a warning of the ramifications of checking a box (right after they've checked it) and then give them a choice to "cancel" their action (and "uncheck" the box automatically) if they would like. Not sure where to put the event, or how to write the event, obviously, but here's what I have that's not working...

Code:
Private Sub chkInactive_BeforeUpdate(Cancel As Integer)
  Dim intResponse As Integer

    intResponse = MsgBox("This record will no longer show in end-user database. Do you want to continue?", _
    vbYesNo + vbQuestion, "Inactivating Record")
    
   If intResp = vbNo Then
     chkInactive.Undo
   Else Me!dateInactivated = date()

   End If
   
End Sub
 
Try changing chkInactive.undo to me.chkInactive=0

HTH,
Eric
 
Dear programmer,

One of the purposes of the beforeupdate-event is to enable you to cancel the action. To this effect there is this parameter Cancel As Integer.
Wutcha use is:
Cancel = True ( or: = 1, or any integer that is not 0 )

The other thing you try to do, "Me!dateInactivated = date()
", should be triggered by the AfterUpdate event, because before that time you can't be sure what value the checkbox ends up with.

Yours truly, Daan
 
Thank you very much Daan and Eric.

My question now is...because I want the person to be able to "reactivate" a record, I would want an alternate message to the effect "This record will now appear in end-user db...sure you want to do this?" With a cancel option, once again.

So I guess my question is, at what point/event can I catch if they are checking or unchecking the box, and then msgbox accordingly?

Here's the code that's working as far as ability to check and uncheck - but msg is inappropriate when they're unchecking:
Code:
Private Sub chkInactive_BeforeUpdate(Cancel As Integer)

Dim intResponse As Integer

    intResp = MsgBox("This record will no longer show in end-user database. Do you want to continue?", _
    vbOKCancel + vbQuestion, "Inactivating Record")
    
   If intResp = vbCancel Then
     Cancel = True

   End If
   
End Sub


Private Sub chkInactive_AfterUpdate()

If Me.chkInactive = True Then
    Me.DateInactivated = Date
Else
    Me.DateInactivated = Null
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top