"José António Silva" <(E-Mail Removed)> wrote in
message news:149BCE74-5BF8-4449-B4A6-(E-Mail Removed)...
> 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).
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)