Deleting Records

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I have a delete button using
DoCmd.RunCommand acCmdDeleteRecord

I can delete records going towards the end of the set if I Start at the
begining but I cant delete records going towards the begining of the
set. Is there a code I can add so that it can go both ways?
Thanks
DS
 
DS,

I am not 100% sure I understand what you mean. But you could try adding
another line to your code, like this...
DoCmd.GoToRecord , , acPrevious

It might also be applicable for you to look at other approaches to this
situation, by using a Delete Query.
 
Steve said:
DS,

I am not 100% sure I understand what you mean. But you could try adding
another line to your code, like this...
DoCmd.GoToRecord , , acPrevious

It might also be applicable for you to look at other approaches to this
situation, by using a Delete Query.
If I'm at the last record in the subform...I hit delete and I get a
Error message.
If I'm at the first record I can hit delete and if I wish I can delete
the next, the next and so on.

I want to be able to if I'm on the last record to hit delete and to be
able to continue deleteing if I choose all the way to the first record.

I hope this is clearer...writing is not my strong point!
DS
 
DS,

Did you try the suggestion I made before? Did it work? If not, what
happened?

If you use the Previous idea, you will also get an error if you are
currently trying to delete the first record, i.e. where there is no such
thing as a previous record. This will fix it, I think...
DoCmd.RunCommand acCmdDeleteRecord
If Me.CurrentRecord > 1 Then
DoCmd.GoToRecord , , acPrevious
End If

Anyway, there should be no error message if you are on the last record
of the subform. There will be if the focus is on a new, unsaved record
below the existing last record... is that what you meant?
 
In addition....

If Allow Additions = No then there's another issue --- when you get down to
only one record left (regardless of what direction you're doing this in) and
you then delete the final record in the record set, then a null record set
will result. If that's the case, the form may not display properly ---

If Allow Additions = Yes then you'll not run into this since Access will
have a ficticious "blank" record at the end for additions. Then when you
delete the final actual record, the user will probably be presented with the
blank record (as if adding a new record).

I suggest that depending on which of the above you employ, definitely test
the desult after the deletion to see if you have just deleted the final
record and take appropriate evasive action!

Bob (@Martureo.Org)
 
Steve said:
DS,

Did you try the suggestion I made before? Did it work? If not, what
happened?

If you use the Previous idea, you will also get an error if you are
currently trying to delete the first record, i.e. where there is no such
thing as a previous record. This will fix it, I think...
DoCmd.RunCommand acCmdDeleteRecord
If Me.CurrentRecord > 1 Then
DoCmd.GoToRecord , , acPrevious
End If

Anyway, there should be no error message if you are on the last record
of the subform. There will be if the focus is on a new, unsaved record
below the existing last record... is that what you meant?
This is what works but......

Private Sub Command59_Click()
On Error GoTo Err_Command59_Click
If Forms!Payment.PaymentSubform!PaymentTypeID = 9 Then
Forms!Payment.Visible = False
DoCmd.OpenForm "ReapplyDeposit", acNormal, , DepositID =
Forms!Payment.PaymentSubform!DepositID

ElseIf Forms!Payment.PaymentSubform!PaymentTypeID = 10 Then
DoCmd.RunCommand acCmdDeleteRecord
Forms!Payment!Text56 = 0
Else
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.GoToRecord , , acPrevious
End If
Exit_Command59_Click:
Exit Sub

Err_Command59_Click:
'MsgBox Err.Description
Resume Exit_Command59_Click

End Sub

Like I said but......I don't know. I'm sure its fishy.
Thanks
DS
 
Bob said:
In addition....

If Allow Additions = No then there's another issue --- when you get down to
only one record left (regardless of what direction you're doing this in) and
you then delete the final record in the record set, then a null record set
will result. If that's the case, the form may not display properly ---

If Allow Additions = Yes then you'll not run into this since Access will
have a ficticious "blank" record at the end for additions. Then when you
delete the final actual record, the user will probably be presented with the
blank record (as if adding a new record).

I suggest that depending on which of the above you employ, definitely test
the desult after the deletion to see if you have just deleted the final
record and take appropriate evasive action!

Bob (@Martureo.Org)
I have it set to yes Additions...butsee my previuos post.
Thanks
DS
 
Back
Top