How to unsave data in the new record

S

sc

I am a programming beginner and using the following codes to copy the data in
the previous record to the new record to save time for the user to do the
data entry:

Private Sub cmdnew_Click()
On Error GoTo Err_cmdnew_Click


DoCmd.GoToRecord , , acNewRec

Exit_cmdnew_Click:
If Me.NewRecord = True Then
Set n = Me.RecordsetClone
n.MoveLast
For i = 0 To n.Fields.Count - 1
If n.Fields(i).Name <> "ForID" And n.Fields(i).Name <>
"Hour" Then
Me.Controls(n.Fields(i).Name) = n.Fields(i)
End If
Next
End If

Forms![switch form]![New Articles]![ForFrm]![forqry subform].Requery
Exit Sub

However, I need to use a button with the code SendKey "{ESC}{ESC}".true to
clear the data when the user does not need to add a record; otherwise, there
will be an additional record when the application is quit. I use tab
control to store forms. Each tab has a form. What I want is when I move to
another tab or quit the application, the data is cleared without the need of
clicking the button with the code SendKeys "{ESC}{ESC}".

I will appreciate anyone who can give me a hand.

Best regards,

SC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top