Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB6 listbox

VB6 listbox

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdatabasehelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tatchung
    wrote on last edited by
    #1

    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 If

    However 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

    D N 2 Replies Last reply
    0
    • T tatchung

      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 If

      However 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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • T tatchung

        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 If

        However 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

        N Offline
        N Offline
        Nanda_MR
        wrote on last edited by
        #3

        Try to this query.

        str="delete from tablename where field name=" & "'" & List1.Items.Text & "';"

        Execute this query then refresh the database and remove the all item from list and add up once again.

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          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

          T Offline
          T Offline
          tatchung
          wrote on last edited by
          #4

          Hey 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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups