Proper procedure needed to reset checkbox to True after Msgbox returns VBNo

K

Kevin

Need the correct procedure for the following:
1. A record's checkbox value = True
2. User clicks checkbox to uncheck and gets a msgbox that
asks.. Are you sure?
3. IF msgbox = vbno Then
4. Return value of checkbox to checked (True)
5. Else value of checkbox = False

Hope this is enough info.
Thanks in advance
 
A

Allen Browne

You could use the check box's AfterUpdate event to undo it if the user backs
out:

Private Sub chk_AfterUpdate()
If MsgBox("Confirm change", vbYesNo+vbDefaultButton2) <> vbYes Then
Me.chk.Undo
End If
End Sub
 
K

Kevin

Allen,
Thanks for the suggestion, but it didn't seem to work for
me.
Just to make sure, I created a new form with a checkbox
control and added the sub you provided to the AfterUpdate
event.
When I click the checkbox the msgbox executes like it
should, but when I click "No" the checkbox checks (or
unchecks) anyway.
Am I missing the obvious or what?

Thanks in advance.
 
A

Allen Browne

The line:
Me.[WhateverYourCheckboxIsCalled].Undo
should return the check box to the state that it was before you started
editing/creating this record.

If you wanted to set it to No, you could use:
Me.[WhateverYourCheckboxIsCalled] = False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top