RecordExit event

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

Guest

Hello everyone.
i 'd like to validate the data entered by a user when he/she exits the current record. unfortunately the before update method is not appropreate because the form updates 3 times while the user is in the current record so because of a subform so this is not a good idea. I tried to use the RecordExit event but it does nt seem to work at all.

1. how can i activate the RecordExit event?

2.is there any other way?
 
Can you detect if the subform causes the code to fire and then bail out but
execute it for the main form?
==========================================================
You can use a procedure like this to validate as many controls as you like
before the record is saved. Note: you don't always have to set Cancel =True.
Your validation could include checking for Null values and simply filling
them in with a "default" value in your code.

If everything passes the validation, there will be no message box because
Cancel will be False and the record will save.

If anything fails, then Cancel will be True and the user will see the
problem and can fix it and try to save the record again.


Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim strMessage As String

If Me![txt1] < 0 Or Me![txt2] > 100 Then
strMessage = strMessage & vbCrLf & "Value must be between 0 and 100."
Cancel = True
End If

If Left$(Me![txtTableName], 3) = "tbl" Then
strMessage = strMessage & vbCrLf & "New table names cannot start with
tbl."
Cancel = True
End If

If IsNull(Me![EmailAddress]) Then
strMessage = strMessage & vbCrLf & "Please enter an E-mail address
before saving the record."
Cancel = True
End If

If Cancel = True Then
MsgBox (strMessage)
End If

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox "Error # " & Err.Number & " was generated by " & Err.Source &
vbCrLf & Err.Description, , "FormName - Form_BeforeUpdate"
Resume Exit_Form_BeforeUpdate

End Sub

--
Joe Fallon
Access MVP



Giannis Isaias said:
Hello everyone.
i 'd like to validate the data entered by a user when he/she exits the
current record. unfortunately the before update method is not appropreate
because the form updates 3 times while the user is in the current record so
because of a subform so this is not a good idea. I tried to use the
RecordExit event but it does nt seem to work at all.
 
The correct event in which to do that, is the form's BeforeUpdate event. If
that event is firing more than once when a single main form record is saved,
something is definitely wrong with the code. The mere presence of a subform
would not cause that to happen, AFAIK. So, I recommend that you (a) find out
the true reason why BeforeUpdate is firing several times; (b) fix that
problem, then (c) use BeforeUpdate for your validations.

As for RecordExit, there is no such event.

HTH,
TC


Giannis Isaias said:
Hello everyone.
i 'd like to validate the data entered by a user when he/she exits the
current record. unfortunately the before update method is not appropreate
because the form updates 3 times while the user is in the current record so
because of a subform so this is not a good idea. I tried to use the
RecordExit event but it does nt seem to work at all.
 
Gak! MSDN shows me loads of new events etc. for Access 2k+.

"Extract foot, close mouth..."

Thanks for the info,
TC
(off for the day)
 
Hi TC
There is a record exit event (I think only in 2002) but if my memory serves
me there was an article in the MS KB about it - something about that it
exists but was left out of the the form's properties. I also remember trying
to make it work a long time ago but couldn't. Here is the info from help on
it:

Occurs just before the user exits the current record.

Private Sub Form_RecordExit(Cancel As Integer)

Cancel Set this argument to True to prevent the user from exiting the
current record.

Remarks
The event occurs after the user has done something to move away from the
current record, either by navigating to another record, closing the form,
refreshing the form, or requerying the form, but before the view of the
current record has been discarded. Use this event to examine records before
they are no longer the current record to ensure that data validation rules
have been met.

Note When a form containing a subform is closed, the main form closes
before the subform. Any events triggered by the subform, including
RecordExit, occur after the main form is already closed. As a result, the
Cancel argument will have no effect and the form will close. Event-driven
validation should therefore be implemented at the form level.

Example
The following example demonstrates the syntax for a subroutine that traps
the RecordExit event.

Private Sub Form_RecordExit(Cancel As Integer)
Dim booValidated As Boolean

' Perform some sort of data validation.

If booValidated = True Then
Cancel = False
Else
MsgBox "Data validation failed!"
Cancel = True
End If

End Sub

Hope this helps
 
TC said:
Gak! MSDN shows me loads of new events etc. for Access 2k+.

"Extract foot, close mouth..."

Thanks for the info,
TC
(off for the day)

When you come back you can remove your foot and pretend it was never in
there.

http://support.microsoft.com/default.aspx?scid=kb;en-us;286477
ACC2002: RecordExit Event Unavailable in Microsoft Access 2002

http://support.microsoft.com/default.aspx?scid=kb;EN-US;286591
ACC2002: RecordExit Event in Employees Form Does Not Work

<quote from KB 286591>
The RecordExit event was an event that existed during the Microsoft
Access 2002 beta cycle, but it was removed in the final release version
of Microsoft Access 2002. The sample applications used this event in the
Employees form; however, the procedure was not removed from the sample
applications after the event was removed from Microsoft Access. Note
that the event procedure will not fire because the RecordExit event no
longer exists in Microsoft Access.
</quote from KB 286591>

http://support.microsoft.com/default.aspx?scid=kb;en-us;304139
ACC2002: How to Programmatically Implement a RecordExit Event

http://support.microsoft.com/default.aspx?scid=kb;en-us;286595
ACC2002: Error When You Run RecordExit Function or Sub Procedure
 
Ian Baker said:
Hi TC
There is a record exit event (I think only in 2002) but if my memory
serves me there was an article in the MS KB about it - something
about that it exists but was left out of the the form's properties. I
also remember trying to make it work a long time ago but couldn't.
Here is the info from help on it:
[snip]

I'm not surprised you couldn't make it work, because the help file is
wrong. There was a RecordExit event in one of the beta versions, but it
didn't make it into the final release.
 
I do remember reading a KB article explaining how to simulate a record
exit event. I think though it required you to access a recordset via the
ADO model not DAO. I used it to get around the MouseWHeel issue but was
not happy with the results. I'm sure if the OP looks he can find the KB
article I am referring to.

Peeking at this thread I would agree with TC that the Form's
BeforeUpdate event is the proper event to handle this validation issue.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
"Stephen Lebans"
I do remember reading a KB article explaining how to simulate a record
exit event. I think though it required you to access a recordset via
the ADO model not DAO. I used it to get around the MouseWHeel issue
but was not happy with the results. I'm sure if the OP looks he can
find the KB article I am referring to.

My reply to TC includes that link.
 
Thanks Dirk
I knew there was something about it but couldn't quit recall exactly what it
was but I remember now trying to play with it - didn't work - looked up the
KB and found out why it didn't work. Its a pity because I could think of
some areas I could use this very easily without having to do workarounds.

--
Regards
Ian Baker
Jackaroo Solutions Melb Aust
Jackaroo IT - an IT Mgmt & Help Desk application at http://jackaroo.net.au
Dirk Goldgar said:
Ian Baker said:
Hi TC
There is a record exit event (I think only in 2002) but if my memory
serves me there was an article in the MS KB about it - something
about that it exists but was left out of the the form's properties. I
also remember trying to make it work a long time ago but couldn't.
Here is the info from help on it:
[snip]

I'm not surprised you couldn't make it work, because the help file is
wrong. There was a RecordExit event in one of the beta versions, but it
didn't make it into the final release.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
thancs everyone for your answers. you have been very helpfull to me. (i ve just read them) i ll try the code to replace the NON EXISTING OnChangeRecord property (thancs Dirk). By the way i really dont know why the beforeupdate() event is executed three times. Actually the procedure is called any time i enter or exit to/from the subform if there are changes in the main form. Really bizzare!!!!!!!!
thancs again
 
Capital!!

Thanks :-)

TC


Dirk Goldgar said:
When you come back you can remove your foot and pretend it was never in
there.

http://support.microsoft.com/default.aspx?scid=kb;en-us;286477
ACC2002: RecordExit Event Unavailable in Microsoft Access 2002

http://support.microsoft.com/default.aspx?scid=kb;EN-US;286591
ACC2002: RecordExit Event in Employees Form Does Not Work

<quote from KB 286591>
The RecordExit event was an event that existed during the Microsoft
Access 2002 beta cycle, but it was removed in the final release version
of Microsoft Access 2002. The sample applications used this event in the
Employees form; however, the procedure was not removed from the sample
applications after the event was removed from Microsoft Access. Note
that the event procedure will not fire because the RecordExit event no
longer exists in Microsoft Access.
</quote from KB 286591>

http://support.microsoft.com/default.aspx?scid=kb;en-us;304139
ACC2002: How to Programmatically Implement a RecordExit Event

http://support.microsoft.com/default.aspx?scid=kb;en-us;286595
ACC2002: Error When You Run RecordExit Function or Sub Procedure

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Giannis Isaias said:
thancs everyone for your answers. you have been very helpfull to me.
(i ve just read them) i ll try the code to replace the NON EXISTING
OnChangeRecord property (thancs Dirk). By the way i really dont know
why the beforeupdate() event is executed three times. Actually the
procedure is called any time i enter or exit to/from the subform if
there are changes in the main form. Really bizzare!!!!!!!! thancs
again

That's not bizarre, that's mandatory. At least, it is mandatory that
the main form record will be saved *if it is dirty* every time the focus
shifts to the subform. This is how Access ensures referential integrity
between the main form and the subform. You cannot suppress this
behavior, only work around it if you're doing something in the
BeforeUpdate event that you only want to do once while flipping back and
forth between the main form and the subform.
 
Back
Top