Logic issue for a checkbox VBA IF statement (1 Viewer)

GoodLife22

Registered User.
Local time
Today, 08:45
Joined
Mar 4, 2010
Messages
86
I have a standard check box in my form. I need write my code that IF the box is NOT checked and then my user goes and clicks on the box it will give a message box.

I first thought of a LOST FOCUS event, but that doesn't help if it wasn't checked and then checked.

I thought about an on change, but that doesn't do it IF it is originally checked and then my user unchecks it.

So what is the best way to do this:

My user loads the record, and IF the [CHKBX1] is currently FALSE, then changes to TRUE, provide message box?

Thanks you.

I currently have (which I know is not going to work for me)

Code:
Private Sub CHKBX1_LostFocus()

If CHKBX1 = True Then
    MsgBox "You have checked the update2012 box. Please remember to send the follow-up email with 4 attachments."
Else
    'do nothing
End If
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,139
Untested, but try the before update event of the form, comparing the OldValue and Value properties of the checkbox. Depending on what you're trying to accomplish, you might also use the after update event of the checkbox (if it's true, it must previously have been false). The hole in that is if the user changes it back and forth.
 

amrizvi

New member
Local time
Today, 17:45
Joined
Jun 21, 2011
Messages
6
Untested, but try the before update event of the form, comparing the OldValue and Value properties of the checkbox. Depending on what you're trying to accomplish, you might also use the after update event of the checkbox (if it's true, it must previously have been false). The hole in that is if the user changes it back and forth.

as I understood, after update event is more approperiate suggested by pbaldy as you dont have to inturrpt the even if occure, you just want a message to display when event occured and before update is useful only when there is chance to inturrpt the event after checking.

Code:
Private Sub CHKBX1_AfterUpdate()
  If CHKBX1 = True Then
    MsgBox "You have checked the update2012 box. Please remember to send the follow-up email with 4 attachments."
  Else
    'do nothing
  End If
End Sub
 
Last edited:

GoodLife22

Registered User.
Local time
Today, 08:45
Joined
Mar 4, 2010
Messages
86
Private Sub CHKBX1_AfterUpdate() If CHKBX1 = True Then MsgBox "You have checked the update2012 box. Please remember to send the follow-up email with 4 attachments." Else 'do nothing End If End Sub
This worked like a charm. This is exactly what I needed. THANK YOU.

Does anyone have a really good cheat sheet explaining the differences between all of the difference EVENT TYPES? There are:

on current
after insert
before update
on dirty
after del confirm
on open
on load (how is that not the same as on open)
on unload (huh? Is that on close?)
on close (nope not the same as unload)
on cmd checked (what)

and they keep going. I am not sure what most of these are, some are clear by the name and others are not. Is there any online resource which explains these in a fairly easy to understand format? Thank you all.
 

Users who are viewing this thread

Top Bottom