How to clear the data copied from the previous record?

G

Guest

Actually, the current data is always copied from the previous record, but I
would like to clear it without saving when I move to another form or close
the Access. I use tabs to store forms. My problem is when I close the
Access, the current data copied from the previous record is saved as a new
record. My boss does not allow me to add an undo button in the form.

I will appreciate it if anyone can offer me a help.

Best regards,

James Wong
 
A

Alex Dybenko

Hi,
probably you can use default value property to set default values for new
record after previous record entered. then, if user did not make any
modifications to new record - it will not be dirty and will no be saved or a
close or whatever
 
G

Guest

Dear Alex,

Many thanks for your help! I will appreciat it if you can let me know how
to code the default values for new record.

Thanks!
 
A

Alex Dybenko

Hi,
what you can try - is to use Form's afterupdate event to set corresponding
textboxes default values to just saved values. then once you start
enteringnew records - these fields will be populated with default values.
Another solution - is to use form's before update event and fill data from
previous record, this should alos work - data will be filled when user
started to enter new and decide to save record.

HTH
 
G

Guest

Hi! Alex,

Many thanks for your help. As I am a programming beginner, I will
appreciate it if you would show me the code on how to unsave the new record
copied from the pervious record. I do not know how to code to set default
values for new record.

Once again, many thanks for your help.
 
G

Guest

Hi! Alex,

More questions, would you let me know how to code to unsave the data in the
new record copied from the previous record when I click the next tab? I use
tab control to store forms.

One more question, how to code to quit the application when I click a tab.

Thanks!

sc
 
A

Alex Dybenko

Hi,
More questions, would you let me know how to code to unsave the data in
the
new record copied from the previous record when I click the next tab? I
use
tab control to store forms.

In case you use default value approach - you dont need to unsave data, as
data not entered, until user start enter
One more question, how to code to quit the application when I click a tab.

you can use Docmd.Quit
 
G

Guest

Dear Alex,

Thanks for your reply.

As you know from the following, I am able to copied the previous record to
the new record except for two fields that I use If condition to exclude them.

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, once the application is quit, the deplicated data in the new record
is also saved that is not what I want. What I want is when the user move to
another tab. the deplicated data will be cleared without being save as a new
record. SendKeys "{ESC}{ESC}".true works, but I need to add an additional
button in the form, and that is also not I want.

Another issue is when I use the code the "docmd.quit" in the "on click
event" of tab control, it won't work unless I click the blank area of the tab
instead of the tab itself. What I want is to click the tab instead of the
area below the tab.

Thank you for your kind attention.

Best regards,

SC
 
A

Alex Dybenko

Hi,
ok, in this case i think you first have to determine - what kind of records
you want to delete, for example records where Hour is not entered. then,
after tab changed, you can just run a delete query and delete such "not
completed" records

for docmd.quit - tyr to use Tab Change event

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com



sc said:
Dear Alex,

Thanks for your reply.

As you know from the following, I am able to copied the previous record to
the new record except for two fields that I use If condition to exclude
them.

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, once the application is quit, the deplicated data in the new
record
is also saved that is not what I want. What I want is when the user move
to
another tab. the deplicated data will be cleared without being save as a
new
record. SendKeys "{ESC}{ESC}".true works, but I need to add an additional
button in the form, and that is also not I want.

Another issue is when I use the code the "docmd.quit" in the "on click
event" of tab control, it won't work unless I click the blank area of the
tab
instead of the tab itself. What I want is to click the tab instead of the
area below the tab.

Thank you for your kind attention.

Best regards,

SC



Alex Dybenko said:
Hi,


In case you use default value approach - you dont need to unsave data, as
data not entered, until user start enter


you can use Docmd.Quit
 

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