Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Carol W.

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    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?
    Wendell

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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.
    Attached Files Attached Files

  4. #4
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Carol W.

  5. #5
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Apologies to WendellB. I somehow, in my haste, thought that Hans had replied twice .

    I need a rest!

    Thanks to you both.
    Carol W.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •