Goto previous EDITED record on continious form

MartijnAn

Registered User.
Local time
Today, 13:58
Joined
Sep 30, 2004
Messages
51
Hi All,

I have a continious form where each record can be edited. After editing a record the form does a me.save and a me.requery (is important). After this it jumps back to the first record (seems logical), but how can I write a code that he goes back to the 'previous edited record'.

Thanks.
 
Good question.

Here is how I do it when I allow the user to recalculate the form. My primary key is the records SSN. Adjust it to meet your needs. [I am not using a continious form but it should work.]

Code:
Private Sub bRecalc_Click()
On Error GoTo Err_bRecalc_Click

    Dim sSSN As String
    
    If Me.Dirty Then
        MsgBox "Please save this record before you attempt to requery the data!", vbExclamation, "Save Required"
        Exit Sub
    Else
        sSSN = tbSSN
        DoCmd.Echo False
        Me.Requery
        Me.tbSSN.SetFocus
        DoCmd.FindRecord sSSN
        DoCmd.Echo True
        sSSN = ""
    End If

    Me.tbHidden.SetFocus

Exit_bRecalc_Click:
    Exit Sub

Err_bRecalc_Click:
    DoCmd.Echo True
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_bRecalc_Click

End Sub
 
Thanks for your reply. It all looks understandable, but:

1) Can you explain the sSSN = tbSSN
2) I do not use a button, can I use this code on a form_activate event?
 
1) Can you explain the sSSN = tbSSN
The string sSSN is equal to the value in the tbSSN text box. That is your 'bookmark' to the current record. That is how the DoCmd.FindRecord sSSN command works.

2) I do not use a button, can I use this code on a form_activate event?
It should work when and where ever you call it.
 
1. Me.Save is an invalid statement. If you mean that you save the current record, that command is
DoCmd.RunCommand acCmdSaveRecord
2. Why are you requering the form? You say it is important but the form doesn't need requerying to show the new record.
 

Users who are viewing this thread

Back
Top Bottom