Link to home
Start Free TrialLog in
Avatar of Galisteo8
Galisteo8

asked on

Run event each time different record is viewed

In Access 2000, I would like to run a certain piece of VB code each time a record is viewed on a form.  Not just when the form opens or when the form is activated, but each time the user moves forward or backward to view other records, or when the user goes to a different record via the search function.

Under which form event should I put my code?

Thanks,
Galisteo8
ASKER CERTIFIED SOLUTION
Avatar of Nestorio
Nestorio

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jim Horn
Nestorio is correct the Form.Current event fires whenever you move from one record to another.
Avatar of Galisteo8
Galisteo8

ASKER

Oh!  Okay.... I thought it was only if something was changed on the record view.... You know: Keeping the record current.  But I guess that's sort of like saying the same thing!  lol
I now have my code stuck into the OnCurrent event of the form.  The code is a Me.Resync statement, designed to sync up the form's current record with the underlying SQL data.  The idea is that if Bob changes, say, Record #10 from his workstation's ADP, then the next time that Susan views Record #10 it will resync itself with the SQL tables and display Bob's changes.  (Otherwise, Susan would be stuck viewing whatever data was in the recordset for Record #10 when she first opened her ADP earlier that day.)  If Susan then hits the nav button to advance to Record #11, then the form will once again Resync the current record and whe will see the most recent data for Record #11.

At least, that's what was supposed to happen -- and it seems that OnCurrent would be the place to do that.

What happens is that Susan navigates to Record #10 and CAN'T see Bob's changes until she 1) goes on to another record and then 2) RETURNS to Record #10.  Basically, she'll see Bob's changes the SECOND time she views Record #10, not the first time.

Using the OnCurrent event in this manner.... would having subforms screw it up so that it takes TWO visits to get the OnCurrent event to be... current?

--Galisteo8
Jimhorn, please see my prior post, regarding your comment that putting the code into the Form.Current event is appropriate if you want it to run each time a new record is viewed.  Why would it take two visits to the same record before I see data changes if my Resync code is running in Form.Current event?
Repeating question:  Using a Me.ReSync command in a form's OnCurrent event, why does it still take TWO VISITS to a particular record for User #1 to see changes that were made to that record by User #2 ???
In the after update event of the form put this:

Private Sub Form_AfterUpdate()
    If Me.Dirty Then
        Me.Dirty = False
    End If
End Sub

Hope this help
Have you tried my answer?
Nestorio,

I'll try it later this week when I am back at that job site.  (Unfortunately, I don't have remote access.)
Nestorio,

Again, I have had other issues popping up that have kep me from getting back to this question.  But I have not forgotten!
No problem.
I remain interested.

The initial suggestion -- to place the Me.Resync statement into the form's OnCurrent event -- produced a strange result which has not yet been resolved.  I will test Nestorios' suggestion, as well as to modify the statement to Me.Recordset.Resync, but I will not be able to do that until Tuesday of this week.  In the meantime, please don't force this question closed.

Thanks,
Galisteo8
I will take Nestorio's original answer as the solution for my question.  The oddity I encountered is apparently due to the vagaries of the Resync command, and are outside the scope of my original question.  If the "must-visit-record-twice" problem continues to be an issue for me, I will address that in a separate question.  I originally just needed to be sure that I was using the proper event (On Current) to run code each time a new record was being viewed.

Nestorio, thanks and sorry for the wait!  
Hi Galisteo, no problem.
Thanks for the points.