Delete selected only....

  • Thread starter Thread starter mo
  • Start date Start date
M

mo

A listbox on a form has the following code which is meant to delete only the
seelcted items from the underlying table, but instead deletes all the
records in the listbox (anf the table). Can anyone see what I'm doing wrong?

Thanks for any help.

Dim db As DAO.Database
Dim strSQL As String
Dim strWhere As String
Dim varSelected As Variant

For Each varItem In Me.lst_selected.ItemsSelected

strWhere = "HospNum = " & "'" & Me.lst_selected.ItemData(varSelected) &
"'"

Next varItem

strSQL = "DELETE * FROM tbl_Lists "
strSQL = strSQL & "WHERE " & strWhere

'Debug.Print strSQL

Set db = CurrentDb()

db.Execute strSQL

Me.list_main.Requery

Set db = Nothing
 
Try this,

For Each varPtr In lstSelected.ItemsSelected
strList = strList & strLink & "'" & lstSelected.ItemData(varPtr) & "'"
strLink=","
Next
strSQL = "Delete * From tblList Where HosNum In (" & strList & ")"

I haven't declared the variables

Rod Scoullar
 
Back
Top