• Opposite of Current Event?

    Author
    Topic
    #461602

    I have a bound form whose record source is a table called tblschools. I need to be able to trap the event that occurs when the user moves from record to record without updating (just viewing the record). I know that the Current event gets fired when the user lands on the next record but I need to be able to detect when the user is about to leave the current record (I call it the “opposite of current”, for lack of a better name).

    I did some Google searching and could not find an event built into Access that does this. I entered “opposite of current” into Google and did find a MS article pertaining to Access 2002 (I’m using 2003) that provides code that does this. Here is the article:

    http://support.microsoft.com/default.aspx?…kb;en-us;304139

    I’m able to insert the class module with no problem. However, when it comes to adding the second block of code to my form I’m getting all kinds of syntax errors and am frankly somewhat lost.

    My questions are:
    1 – Is there an easier way of doing this?

    2 – If I need to resort to the method described in MS’s article, where in the form code does their code get inserted?

    Thanks, in advance.

    Viewing 3 reply threads
    Author
    Replies
    • #1171803

      The Microsoft article indicates that it is advanced and requires expert coding skills. Anything using class events is complex conceptually, and usually a challenge to implement. You don’t indicate whether this is a continuous form or a single record viewing form, but if it is a single record viewing form, one options would be to change the navigation property of the form to make the record stay on the same record when Tab or Enter is pressed, and remove the navigation controls on the bottom of the form. Then you could add your own button to move to the next record and record any info you need at that point.

      Now for the $64K question: Why do you want to trigger an event when the record is left? The only reason I can think of is to count the number of times a particular record was viewed. Is that it?

    • #1171807

      As the MSKB article indicates, Access itself does not provide an event that occurs when the user leaves a record. Hence the need to use the WillMove event of the recordset associated with the form. There is no easier way to do this, as far as I know.

      You should ask yourself whether you REALLY need this. In over 10 years of developing Access databases, I’ve never encountered the need for a “before exit record” event. Unless it’s essential I’d avoid setting up the code.

      If you do need it, you should clear the record source of the form, and set the recordset in the On Load event instead, as in the article.

      I have attached a small sample database using the Employees table from the Northwind sample database.

      • #1171815

        Hans,

        Thanks, as always, for your replies.

        The answer to the $64,000 question is that I added a new field to the tblschools record called area. I want to ensure that this new field is populated when the user leaves the record, even if the record hasn’t otherwise been updated. There probably are better ways of doing this but this is the only method I could think of off the top of my head.

        I actually got the MSKB code to work! The Private WithEvents fRecExit As CRecordExit statement goes at the top with the other declarations. The fRecExit_fRecordExit routine goes at the bottom and the remainder of that second block of code goes in the On Load event.

        I’ve actually modified the code to check the area field and the user is now unable to leave a record (even if only viewing) if the area field isn’t filled in. I’m pretty proud of myself and I learned something too (always important )

        Thanks again.

    • #1171824

      Apologies to WendellB. I somehow, in my haste, thought that Hans had replied twice .

      I need a rest!

      Thanks to you both.

    • #2570077

      It is insane that I am asking this EXACT question 14 years after it was originally posted. While I did not find my answer here and will continue looking, I have a GENUINE, non-replaceable-by-other-coding-techniques (as far as I know), BONAFIDE, use case for a “Before Exiting Record” event.
      I have a continuous-form subform (SubA) that acts as a master list. The active record  from SubA controls another continuous-form subform, SubB, which displays records from a different table that relate back to the selected/active record from SubA.
      The user may make any multitude of changes on SubB. The underlying table for SubA has a status field. The status field is not binary, nor even trinary, but is 6- or 7-nary. And it is determined by an incredibly complex set of interactions of the values of the fields in SubB.
      I need to calculate the status as the user leaves the record. There is a status indication on the master list. On current only allows the status to be updated if the user selects that record from the master list. There are other factors that I am glancing over, but a “Before Exiting Record” Event would the only real solution to fit my exact use case

      If anyone bothers responding asking details in order to form a rebuttal, I would welcome the challenge.

      -ZkO Rx

    Viewing 3 reply threads
    Reply To: Opposite of Current Event?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: