Undo changes in a form

E

Erod1980

I'm trying to catch duplicates in an access form. I have a series of queries
that looks for in between dates for contracts. If the query catches a dup
record then it checks off a hidden dup field in the form. I want the form to
undo all changes if this dup record field is true. On click of a button, it
runs the queries, and checks the Dup field. It was working for me at first,
but then it stopped working. Here is the code:


Private Sub cmdSaveChanges_Click()
Call Mods1.UserName

If Me.Dirty = True Then

Me.Refresh

Me.LastModDate = Now()
Me.LastModUserID = user()

DoCmd.RunMacro "mcCCG.UndoDupModWri"

Me.Refresh

If Me.chkDupDates = True Then

DoCmd.RunCommand acCmdUndo

End If
End If

End Sub

Plesae let me know what I can do to achieve this.
Thanks!
Enrique
 
P

Pat Hartman

Undo will not work after the record has been committed. Once you save the
record, you need to delete it if you want to get rid of it.

BTW - using Me.Refresh is a poor way to save the current record. If you
want to save a record use:

DoCmd.RunCommand acCmdSaveRecord
 
J

Jeanette Cunningham

If this is a bound form, you can use the before update event of the form to
catch duplicates and stop them being saved in the table.
You do a DCount or DLookup using the value or values the user has entered to
see if they are already in the table.
If it is a duplicate, then in the before update event of the form, you set
Cancel = True and pop up a message box telling the user about the problem.

Jeanette Cunningham
 
J

Jeanette Cunningham

To prevent duplicates, you can set up validation rules for fields in the
table or for the table itself. This is in addition to validation in the
before update event of the form. In fact this is recommended - if ever you
import data without going through a form which checks for duplicates before
it adds imported data, you could unintentionlly add duplicate data. If you
have the validation against duplicates in the table as well you are well
protected from duplicates.

Jeanette Cunningham
 

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