How to clear data copied from the previous record

S

sc

I use the following code to copy data from the previous
record except for two fields:

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, when the user closes the application, a
duplicated data will be save in a new record. If the
user does not make any changes in the current record, can I
clear it out before the user closes the application?

I will appreciate anyone who can give me a code example.

Best regards,

SC
 
A

Andreas

You could use the forms BeforeUpdate event to compare the data against
the data written to the controls. If it is the same, Undo the changes.

Regards,
Andreas
 
J

John Smith

Rather than setting the value of the controls, set the DefaultValue property.
This will only result in a record being written if the user actually types
something into the record as well.

Me.Controls(n.Fields(i).Name).DefaultValue = n.Fields(i)

Also, in case you are not aware of this, unless your recordset is sorted you
cannot guarantee which record you will get to by a MoveLast.

HTH
John
 

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