• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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
0
Galisteo8
Asked:
Galisteo8
  • 8
  • 5
1 Solution
 
NestorioCommented:
I think it is the On current event of the Form:

Private Sub Form_Current()

End Sub
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Nestorio is correct the Form.Current event fires whenever you move from one record to another.
0
 
Galisteo8Author Commented:
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
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
Galisteo8Author Commented:
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
0
 
Galisteo8Author Commented:
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?
0
 
Galisteo8Author Commented:
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 ???
0
 
NestorioCommented:
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
0
 
NestorioCommented:
Have you tried my answer?
0
 
Galisteo8Author Commented:
Nestorio,

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

Again, I have had other issues popping up that have kep me from getting back to this question.  But I have not forgotten!
0
 
NestorioCommented:
No problem.
0
 
Galisteo8Author Commented:
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
0
 
Galisteo8Author Commented:
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!  
0
 
NestorioCommented:
Hi Galisteo, no problem.
Thanks for the points.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now