How to delete just one record?

  • Thread starter Thread starter José António Silva
  • Start date Start date
J

José António Silva

Is there any way to prevent users from selecting more than one record in a
datasheet form view and try to delete them all at once?

I need to make some stuff when a record is deleted, and I code it in the ‘on
delete’ event. The problem arises when I need to compute a maximum date over
the same table where the user is deleting, perhaps, some records. Since the
form creates itself a transaction to delete all the selected records, I will
get an error because my code waits indefinitely by the ODBC answer of maximum
date.

If the user deletes just one record, this won’t happen. My code stops when
trying to compute maximum date for a second record select for deletion at
once.

Any help will be welcome,
Thanks,
JS
 
Not to my knowledge. Instead of giving them access to the datasheet view, go
with a continuous form that includes the fields that they need.
 
José António Silva said:
Is there any way to prevent users from selecting more than one record in a
datasheet form view and try to delete them all at once?

I need to make some stuff when a record is deleted, and I code it in the
‘on
delete’ event. The problem arises when I need to compute a maximum date
over
the same table where the user is deleting, perhaps, some records. Since
the
form creates itself a transaction to delete all the selected records, I
will
get an error because my code waits indefinitely by the ODBC answer of
maximum
date.

If the user deletes just one record, this won’t happen. My code stops when
trying to compute maximum date for a second record select for deletion at
once.


In the form's Delete event, you can check the form's SelHeight property to
see if more than one record is selected, and cancel the delete in that case.
For example:

Private Sub Form_Delete(Cancel As Integer)

If Me.SelHeight > 1 Then
Cancel = True
Else
' ... do the original work ...
End If

End Sub

Unfortunately, you can't easily display a message to the user explaining why
the delete was cancelled, because the message will be displayed for every
selected record (as the Delete event fires for each record).
 
Back
Top