Check Box Message

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have recently managed (with the help of another forum user, these
forums are great aren't they?) to lock out fields when a check box is checked
and vice-versa.

However, is there anyway that I can make a message pop-up when they uncheck
it to say something like "you will now be able to edit this record, are you
sure?"
 
Yes, it shouldn´t be any problem.

Add the following code to the checkbox click_event:

' Code starts here

' If the checkbox is NOT True = unchecked then ask user with a MsgBox
If Not Me.NameOfYourCheckBox Then

' If user answer YES then exit sub and continue else set your checkbox
to True = checked
If MsgBox("You will now be able to edit this record, are you sure?",
vbQuestion + vbYesNo, "Edit records") = vbYes Then

Exit Sub

Else

' Cancel the event and set checkbox
DoCmd.CancelEvent
NameOfYourCheckBox = True

End If

End If

I hope this will help you out. Don´t forget to change < NameOfYourCheckBox >
to the correct name of your checkbox in the form.

// Niklas
 
Excellent Niklas, 99% of it works great, it just needs tweaking I guess, this
is superb!

Only thing happening now is when you click the check-box to remove the tick,
it gives me the message box (great), clicking yes, removes the tick and
allows me to edit (great, well happy with that!)

If I select No at the message box, it leaves the tick in the box (great) but
allows me to Edit the record (hmmn), where it shouldn't as the cells should
be locked when the box is checked.

And the only way to lock the cells is to uncheck it again, select Yes, then
check the box again, this way it locks the cells again.

Any ideas?

Thanks so far though, I have got further than ever before.
 
Hi again!

I´m in a hurry but yes I know what can solve your problem.

I have added "DoCmd.Requery" in the code below. This requery (update) the
underlying recordset of the form and shouyld help you out here:


' Code starts here

' If the checkbox is NOT True = unchecked then ask user with a MsgBox
If Not Me.NameOfYourCheckBox Then

' If user answer YES then exit sub and continue else set your checkbox
to True = checked
If MsgBox("You will now be able to edit this record, are you sure?",
vbQuestion + vbYesNo, "Edit records") = vbYes Then

Exit Sub

Else

' Cancel the event and set checkbox
DoCmd.CancelEvent
NameOfYourCheckBox = True
DoCmd.Requery

End If

End If

' Code ends here


I hope this help you out because I don´t have more time until later this
eavning, when I will check in again and se if you need any more help!

// Niklas
 
Back
Top