MsgBox before you can check the box

Pusher

BEOGRAD Put
Local time
Today, 21:48
Joined
May 25, 2011
Messages
230
Hi all,
I want to make an MsgBox popup when i click on a check box with a message - if the two controls are not filled you can’t check this box – if they are filled then nothing happens an the box is checked. How do I do this?
Thanks
 
I would use the BeforeUpdate event of the Checkbox.

Code:
Private Sub yourField_BeforeUpdate(Cancel as Integer)
Cancel=false
' If Field1 is Empty then Cancel = True
Cancel = Cancel OR (nz(Me.Field1, "") = "")
' If Field2 is Empty then Cancel = True
Cancel = Cancel OR (nz(Me.Field2, "") = "")

If Cancel = True Then
' If Cancel = True then show message
  MsgBox "If the two controls are not filled you can’t check this box ", vbInformation + vbOkOnly
End if
End Sub
 
In the Check box's Before Update event use something along the lines of;
Code:
    If IsNull(Me.Control1) Or IsNull(Me.Control2) Then
        MsgBox "You can't do that"
        Cancel = True
        Me.Undo
        Exit Sub
    End If
This assumes that the native state of your two controls is Null, and that you don't want to allow the Check Box action if either of your controls is blank.
 
How do i make so that those same two boxes are needed for making a new record (doesn’t make a new record if they are not filled and popup an MsgBox with that warning), but not in a table, required option.
 
Does the following in the Form's Before Update event do what you are after;
Code:
    If IsNull(Me.Field1) Or IsNull(Me.Field2) Then
        MsgBox "Both Field 1 and Field 2 must hold data before can move to, or create, another record"
        Cancel = True
        Exit Sub
    End If
Note; This code will not fire if the user scrolls through an existing record that does not have data in both fields. It will only fire if the user makes a change to an existing record, that does not have data in both fields, is amended or the user tries to leave a record with either field 1 or 2 blank.
 
It works but when i enter a new record and not fill the required fields i want him NOT to save it in to the table. He saves it when i go to exit (x) on my form. How do i NOT save that record?
 
It works but when i enter a new record and not fill the required fields i want him NOT to save it in to the table. He saves it when i go to exit (x) on my form. How do i NOT save that record?

:confused: That's pretty much what Cancel = True in the Form's Before Update event does. It stops current changes being committed to the Record Source.
 

Users who are viewing this thread

Back
Top Bottom