Previously used/opened record

  • Thread starter Thread starter royfarnol
  • Start date Start date
R

royfarnol

I would like to have a button to hit to get me to my previously opened/used
record. Can anybody please oblige me with some code to achieve that?

Thanks, RF.
 
Define "previously"...

No, seriously, until you can tell Access HOW to find the "previous" record,
Access won't know what to do.

By "previously opened/used" do you mean "most recently" (a single record) or
ALL records that have been opened/used.

If the latter, since when?

If a record is only "opened" (?looked at but not changed?), does that count?

What do you mean by "used"? Does that mean altered?

More info, please...!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
to get me to my previously opened/used record.
A little more information. How long ago? How used?
 
Say I look at record 27 and this record suggests to me that I ought to
lperhaps look at record 14 when I look at record 14 I would like to be able
to hit a return button to get back to record 27 without necessarily having
altered anything in record 14.

When I get back to record 27 the button then presumably would/should/could
take me back to record 14 if I so desired.

I hope that is clearer. Thanks Roy.
 
I can think of several ways to do this.

One way involves two variables to track the primary key of the records and the
current event of the form.

Assumption: the primary key of the record is a long integer (or autonumber)

'Declare the two variables in the Declarations section of the form module.

Dim lCurrent as Long, lPrevious as Long

Private Sub Form_Current()

If Not(Me.NewRecord) Then
lPrevious = lCurrent
lCurrent = Me.PrimaryKey
End IF

End Sub

Now as you move from record to record you will always have the primary key of
the current and previous record to use in returning to the previous record.
If lPrevious is zero then you have no previous record.

The button code would depend on what your recordset was. In many of my
databases the user is working with only ONE record at a time and the recordset
consists of only one record.

There is a small problem with the above in that a new record won't have a
value and if you delete a record you can't return to it. That implies that
you will need to control lPrevious and lCurrent in the Delete and Insert events.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Thanks I'll give that a go. Roy.

John Spencer said:
I can think of several ways to do this.

One way involves two variables to track the primary key of the records and
the current event of the form.

Assumption: the primary key of the record is a long integer (or
autonumber)

'Declare the two variables in the Declarations section of the form module.

Dim lCurrent as Long, lPrevious as Long

Private Sub Form_Current()

If Not(Me.NewRecord) Then
lPrevious = lCurrent
lCurrent = Me.PrimaryKey
End IF

End Sub

Now as you move from record to record you will always have the primary key
of the current and previous record to use in returning to the previous
record. If lPrevious is zero then you have no previous record.

The button code would depend on what your recordset was. In many of my
databases the user is working with only ONE record at a time and the
recordset consists of only one record.

There is a small problem with the above in that a new record won't have a
value and if you delete a record you can't return to it. That implies
that you will need to control lPrevious and lCurrent in the Delete and
Insert events.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Back
Top