VB6 listbox
-
Hello all! How can I delete listbox contents populated through a database? Here's my code for the delete button...
If Adodc1.Recordset.RecordCount <> 0 Then
res = MsgBox("Are You Sure You Want To Delete This Record?", vbYesNo, "System Message")
If res = vbYes Then
Adodc1.Recordset.Delete
Adodc1.Recordset.Requery
Adodc1.Refresh
MsgBox "Recored has been Deleted"
lstpromo.RemoveItem lstpromo.ListIndex
End If
Else
MsgBox "No Record to delete"
End IfHowever I get the error "Either BOF or EOF is true, etc...". Is there a method in vb6 that I can use like the in odbccommand in .Net?
Aim small, miss small
-
Hello all! How can I delete listbox contents populated through a database? Here's my code for the delete button...
If Adodc1.Recordset.RecordCount <> 0 Then
res = MsgBox("Are You Sure You Want To Delete This Record?", vbYesNo, "System Message")
If res = vbYes Then
Adodc1.Recordset.Delete
Adodc1.Recordset.Requery
Adodc1.Refresh
MsgBox "Recored has been Deleted"
lstpromo.RemoveItem lstpromo.ListIndex
End If
Else
MsgBox "No Record to delete"
End IfHowever I get the error "Either BOF or EOF is true, etc...". Is there a method in vb6 that I can use like the in odbccommand in .Net?
Aim small, miss small
Your code isn't deleting specific records in the database. You're going through the listbox, but not matching those items to records in the recordset. You're not even looking at the first record in the recordset. Judging by your verbage, you're not binding the listbox (if that's even possible in VB6) to the recordset. This means that you have to look at each item in the listbox, find the corresponding record in the recordset, then delete that record, and continue with the search.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Hello all! How can I delete listbox contents populated through a database? Here's my code for the delete button...
If Adodc1.Recordset.RecordCount <> 0 Then
res = MsgBox("Are You Sure You Want To Delete This Record?", vbYesNo, "System Message")
If res = vbYes Then
Adodc1.Recordset.Delete
Adodc1.Recordset.Requery
Adodc1.Refresh
MsgBox "Recored has been Deleted"
lstpromo.RemoveItem lstpromo.ListIndex
End If
Else
MsgBox "No Record to delete"
End IfHowever I get the error "Either BOF or EOF is true, etc...". Is there a method in vb6 that I can use like the in odbccommand in .Net?
Aim small, miss small
-
Your code isn't deleting specific records in the database. You're going through the listbox, but not matching those items to records in the recordset. You're not even looking at the first record in the recordset. Judging by your verbage, you're not binding the listbox (if that's even possible in VB6) to the recordset. This means that you have to look at each item in the listbox, find the corresponding record in the recordset, then delete that record, and continue with the search.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Hey thanks! Kind of a noobish question there but thanks for the aid. Incidentally I wasn't matching the items to the recordset as you said. Got used to vb.net DB manipulation I forgot it was different here in VB6. Agin thanks for the help :-D
Aim small, miss small