Access 2000 Delete ADDs a New record? Help

  • Thread starter Thread starter bobdydd
  • Start date Start date
B

bobdydd

Access 2000 Windows XP

Hi Everybody

I have got a weird one here.

I have a large form frmTransactions based on a single table
tblTransactions.

There are a lot of fields on the form but everything works OK. That is
until you want to delete a record on the EOF that not much data has
been entered. Where the user has started a new record without
completing it and just got the TransactionID entered.

So now I want them to be able to delete this record:
I have tried
DoCmd.RunCommand acCmdDeleteRecord
and I've tried
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

But no joy.

Now here is the strange bit. As I delete this record it ADDs another
one with the autonumber, and I actually see one TransactionID disappear
and a higher one appear. Twighlight Zone stuff I think.

THis not happening with another form that I experimented with, or on
the table itself.

Any help would be most appreciated.

Bob
 
bobdydd said:
Access 2000 Windows XP

Hi Everybody

I have got a weird one here.

I have a large form frmTransactions based on a single table
tblTransactions.

There are a lot of fields on the form but everything works OK. That is
until you want to delete a record on the EOF that not much data has
been entered. Where the user has started a new record without
completing it and just got the TransactionID entered.

If a new record has not yet been saved, then it cannot be deleted. You just
need to cancel the insertion.

If Me.NewRecord Then
'record never saved. just cancel it
Me.Undo
Else
'cancel any current changes
Me.Undo
DoCmd.RunCommand acCmdDeleteRecord
End If

I structured the above for clarity. Obviously you could just have a single Undo
before the If-Then block.
 
Hi Rick

I altered it slighltly and it worked

DoCmd.RunCommand acCmdDeleteRecord
If Me.NewRecord Then
'record never saved. just cancel it
Me.Undo
Else
'cancel any current changes
Me.Undo
DoCmd.RunCommand acCmdDeleteRecord
End If

Thanks a lot
 
bobdydd said:
Hi Rick

I altered it slighltly and it worked

DoCmd.RunCommand acCmdDeleteRecord
If Me.NewRecord Then
'record never saved. just cancel it
Me.Undo
Else
'cancel any current changes
Me.Undo
DoCmd.RunCommand acCmdDeleteRecord
End If

Thanks a lot

It looks to me like that's going to delete two records, most of the
time -- the current one, and the one after it. Are you sure it's doing
what you want?
 
Hi Dirk
Thanks for pointing that out. I have changed it to:

DoCmd.RunCommand acCmdDeleteRecord
If Me.NewRecord Then
'record never saved. just cancel it
Me.Undo
End If

Which ssems to do the trick
 
bobdydd said:
Hi Dirk
Thanks for pointing that out. I have changed it to:

DoCmd.RunCommand acCmdDeleteRecord
If Me.NewRecord Then
'record never saved. just cancel it
Me.Undo
End If

Which ssems to do the trick

I still think you've got a problem there, and maybe you have error
messages turned off and aren't seeing it. What was wrong with the code
Rick Brandt originally posted? That code looks right to me.
 
Dirk Goldgar said:
It looks to me like that's going to delete two records, most of the
time -- the current one, and the one after it. Are you sure it's doing
what you want?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top