Problem deleting the current Record in a subform

B

Byron

I am using Access 2002 and have tried many things but I
still do not have this correct.
I need to delete the current record in a subform using a
command button and if there are other existing records in
the subform move to the previous record.
I am currently using code that I have modified, which I
have used before, from Dev Ashish's web site, as follows:
msgStr = "Delete Current Record?" & vbNewLine &
vbNewLine & " " _
& "Are sure you want to delete the
current ""Contact Times"" record?"
vbResponse = MsgBox(msgStr, vbQuestion + vbYesNo +
vbDefaultButton2, "Delete Record?")
If vbResponse = vbYes Then
With Me.RecordsetClone
.Bookmark = Me.Bookmark
.Delete
Me.Requery
End With
End If

I get a message: "Record has been deleted" when the code
gets to the Me.Requery and the code stops.
What am I missing?
 
C

cd

Not sure about the code you are attempting, but here is
code that I have used before to delete a record and move
to the previous record, unless the record is the first
record for the group.

Dim db As DAO.Database
Dim recClone As Recordset

Set db = CurrentDb()
Set recClone = Me.RecordsetClone
recClone.Bookmark = Me.Bookmark

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True

If Not recClone.BOF Then
DoCmd.GoToRecord , , acPrevious
Me.(Insert field of focus here).SetFocus
End If

recClone.Close
db.Close

I think this is a little cleaner than what you are
attempting, but that is my opinion, everyone has their own
way of programming.

Good Luck!
 
B

Byron

Thanks for the reply.
I have tried your code and I am still not able to complete
the transaction without errors.

I have been using this code for sometime:
With Me.RecordsetClone
.Bookmark = Me.Bookmark
.Delete
Me.Requery
End With

and I have tested it again in Access 97 and it works as
expected. However, when I attempt to use in Access 2002 I
get the errors and it does not work as it should.

Does anyone have any ideas as to why?

Byron
 

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