From: Lau via AccessMonster.com on
I took your suggestions and used Dcount as indicated. However, I was not
able to trigger BeoreUpdate event. I moved the code to OnCurrent and now
with Dcount statement highlighted, I receive an error "Run time '2001'. You
canceled the previous operation."

Thanks.

--
Message posted via http://www.accessmonster.com

From: Jeanette Cunningham on
In Access, the before update event triggers when you close the form or move
to a different record or create a new record.
However, if the form is not dirty, before update will not do anything to
ensure that there is a head of household.
There is a bug when you put your own close button the form - you need to use
the code for
If Me.Dirty = True Then
Me.Dirty = False
End If

to trigger the before update event when user clicks your close button.

Step1 is to make sure your DCount code is working correctly.
Step 2 is to put that code in the before update event and make sure that the
before update event is triggered when the form closes or moves to a
different record, or user clicks out of subform on to main form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia



"Lau via AccessMonster.com" <u46349(a)uwe> wrote in message
news:a688c35c7d213(a)uwe...
>I took your suggestions and used Dcount as indicated. However, I was not
> able to trigger BeoreUpdate event. I moved the code to OnCurrent and now
> with Dcount statement highlighted, I receive an error "Run time '2001'.
> You
> canceled the previous operation."
>
> Thanks.
>
> --
> Message posted via http://www.accessmonster.com
>


From: Lau via AccessMonster.com on
Below are my latest codes on the main form. They do not seem to trigger the
event. Anybody spots any mistake? Thanks!

**********************
BeforeUpdate event
**********************
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me!house_num) Then
If DCount("[household_id]", "tbl_family", "[household_id] = " & Me!
sbf_family!household_id & " AND Me!sbf_family!relationship_id = 'AA'") > 0
Then
MsgBox ("Testing - You are dandy!"), vbOKOnly
Else
'if no household is chosen, prompt to select one
MsgBox ("You must select a family member to be a Head of Household."),
vbOKOnly
Cancel = True
End If
End If
End Sub

****************
OnDirty event
****************
Private Sub Form_Dirty(Cancel As Integer)
If Me.Dirty = True Then
Me.Dirty = False
End If
End Sub

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201004/1

From: BruceM via AccessMonster.com on
If you update the data on the form, then exit the record by using the built-
in navigation buttons, attempting to close the form, or by other means,
Before Update should run. However, it will only run if the data have been
updated. If you don't change anything, there is nothing to update.

If you have your own Close button or navigation buttons, use Me.Dirty = False
as the first line of code. There is no point to putting the code in the
form's Dirty event. I don't use that event much, but I believe it runs as
soon as you "dirty" the record (by typing, for instance). I think that if
you save the record in the form's Dirty event you will do so after every key
stroke, combo box selection, etc. Probably not what you want.

If you use the built-in Access buttons only there is really no place for the
Save code (at least not for record navigation), but then again it is not
necessary if using the built-in buttons. It isn't always necessary when
using your own navigation and close buttons, but there are some bugs, so I
routinely force a save.

Jeanette showed one way of doing this:
If Me.Dirty = True Then
Me.Dirty = False
End If

I tend to use:
Me.Dirty = False

I have heard that Jeanette's way is faster, but whatever difference there is
between the two is very slight.

Lau wrote:
>Below are my latest codes on the main form. They do not seem to trigger the
>event. Anybody spots any mistake? Thanks!
>
>**********************
>BeforeUpdate event
>**********************
>Private Sub Form_BeforeUpdate(Cancel As Integer)
> If Not IsNull(Me!house_num) Then
> If DCount("[household_id]", "tbl_family", "[household_id] = " & Me!
>sbf_family!household_id & " AND Me!sbf_family!relationship_id = 'AA'") > 0
>Then
> MsgBox ("Testing - You are dandy!"), vbOKOnly
> Else
> 'if no household is chosen, prompt to select one
> MsgBox ("You must select a family member to be a Head of Household."),
>vbOKOnly
> Cancel = True
> End If
> End If
>End Sub
>
>****************
>OnDirty event
>****************
>Private Sub Form_Dirty(Cancel As Integer)
> If Me.Dirty = True Then
> Me.Dirty = False
> End If
>End Sub

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201004/1

From: Lau via AccessMonster.com on
Yes, I use the default built-in navigation buttons. Also, I update records
and page back-and-forth, but still it just goes through one record to another
like there is no BeforeUpdate event. As you can see, I even put the
statement

MsgBox ("Testing - You are dandy!"), vbOKOnly

to test for condition that meets the criteria. Nothing happens. I find it
hard to believe myself.

Thank you.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201004/1