problem with deleting a highlighted item on a data sheet

  • Thread starter Thread starter vin defalco
  • Start date Start date
V

vin defalco

i have a datasheet containing sheetmetal items it stands
as a subform data is entered one at a time if an error is
made the user can highlite the item and a delete button
is depressed and the item disappears it works great
except if an item is not highlited the entire file is
gone. here is the vb code for the button.

Private Sub btnRemovePiece_Click()
Dim pieceID, response

With Controls("lstSheetmetalData")
pieceID = .ItemData(.ListIndex + 1)
End With

If IsNull(pieceID) Then
MsgBox "A material must be selected in order to remove
it. Please try again." ***THIS INSTRUCTION DOES NOT
WORK***
Exit Sub
End If

response = MsgBox("Are you sure you want to remove this
piece?", vbYesNo)

If response = vbYesNo Then
CurrentDb.Execute "Delete FROM tblSheetmetal WHERE
id= & pieceID
Recalc
End If
End Sub


when nothing is highlighted and yes to delete is
depressed the entire file is deleted

Please help

thanks vinny
 
I haven't tested this, but just from looking at the code, the only way I can
see for your test to fail is that .ItemData is returning something other
than Null when no record is selected. Try this ...

With Controls("lstSheetmetalData")
pieceID = .ItemData(.ListIndex + 1)
End With
Debug.Print pieceID
Exit Sub

What do you see in the Immediate window when no record is selected?

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Back
Top