Create a Last Viewed Record Button in Microsoft Access
Question details
Create a way to return to recently viewed product records in a Microsoft Access form.
- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A user searches for products and wants to revisit records in viewing order rather than record order.
- Observed behavior
- The standard navigation buttons move through the form's record order, not the user's viewing history.
Identify the product form and its unique numeric product ID field. The example assumes an AutoNumber or Long Integer field named ProductID and a form whose record source includes the records you want to revisit.
Track viewed product IDs with a VBA back button
Use a form-level collection to return to previously viewed products one at a time during the current form session.
The form's Current event records the previous product ID whenever the user moves to a different record. The button finds the most recent ID in the form's current recordset and removes it from the history after navigation.
History is cleared when the form closes. If a search or filter excludes an earlier product, clear or broaden the filter before trying the button again.
Open the product form in Design View. Add a Command Button, set its Name property to cmdBack, and set its caption to Last Viewed.
Select the form, open its Property Sheet, and set the On Current event to [Event Procedure]. Click the adjacent ellipsis to open the VBA editor. If the form already has a Form_Current procedure, integrate the history logic into it rather than adding a duplicate procedure.
In the form's VBA module, add the following declarations and procedures. Replace ProductID with your unique numeric field name if necessary: Private mHistory As Collection Private mCurrentID As Variant Private mGoingBack As Boolean Private Sub Form_Current() Dim id As Variant If Me.NewRecord Then Exit Sub id = Me!ProductID.Value If IsNull(id) Then Exit Sub If mHistory Is Nothing Then Set mHistory = New Collection If Not mGoingBack And Not IsEmpty(mCurrentID) Then If id <> mCurrentID Then mHistory.Add mCurrentID End If mCurrentID = id End Sub Private Sub cmdBack_Click() Dim rs As DAO.Recordset Dim target As Long On Error GoTo Failed If mHistory Is Nothing Then Exit Sub If mHistory.Count = 0 Then MsgBox "There are no earlier viewed records." Exit Sub End If target = CLng(mHistory(mHistory.Count)) Set rs = Me.RecordsetClone rs.FindFirst "[ProductID] = " & target If rs.NoMatch Then MsgBox "The earlier record is not in the current recordset. Clear or broaden the search filter and try again." rs.Close Exit Sub End If mGoingBack = True Me.Bookmark = rs.Bookmark mGoingBack = False mHistory.Remove mHistory.Count rs.Close Exit Sub Failed: mGoingBack = False MsgBox "Could not return to the earlier record: " & Err.Description If Not rs Is Nothing Then rs.Close End Sub
Select cmdBack in Design View and set its On Click event to [Event Procedure]. Save the form, open it in Form View, visit several products, and click Last Viewed repeatedly to return through the history.

Use WPS Office for compatible documents and spreadsheets
WPS Office is a free, lightweight alternative for everyday documents and spreadsheets, with a familiar interface and Microsoft Office format support to make migration easier. It does not run Access forms or fix Access VBA navigation.

Frequently Asked Questions
Why don't Access navigation buttons return to the last product I viewed?
The built-in buttons move through records in the form's current order. They do not maintain a viewing history, so a back button needs custom tracking such as a VBA collection.
Can I return through more than one previously viewed record?
Yes. With the collection-based button, click Last Viewed repeatedly to move back through earlier product IDs recorded while the form remains open.
Why does the button say an earlier record is not in the current recordset?
A search or filter may have excluded that product. Clear or broaden the form's filter or search results, then click Last Viewed again.
Does the viewing history remain after I close the form?
No. The form-level collection is temporary. For persistent history, store viewed IDs in a table and manage their order with additional VBA.




