Results 1 to 2 of 2

Thread: Removing Records from a Database

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Removing Records from a Database

    I need to be able to cycle through all of the fields in a database while cycling through the values in a listbox to see if records exist in the database with a certain field, "identifier", that maches the value of the listbox in that cycle...


    understand?


    This is what i have so far... but it doesn't even look as if it even got started... the records are still in the dbase...

    VB Code:
    1. For i = 0 To lstImport.ListCount
    2.     For j = 1 To RS.RecordCount
    3.         If RS.Fields("identifier").Value = lstImport.List(i) Then
    4.             RS.Delete
    5.             RS.Update
    6.         End If
    7.         RS.MoveNext
    8.     Next j
    9. Next i

    i know that the looping code is good, i believe my problem is in the location of the Delete, Update, and MoveNext commands...

    thank you
    squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    I think you should build a sql statement and then execute that.
    Makes it cleaner and leaves the job to the db.

    VB Code:
    1. Dim SQL As String
    2. Dim db As Database
    3. Set db = opendatabase("yadidasdifoafj some db.mdb")
    4. For i = 0 To lstImport.ListCount
    5.     SQL = "DELETE * FROM TableNameHere WHERE FieldNameHere='" & lstImport.List(i) & "'"
    6.     db.Execute
    7. Next i
    -= a peet post =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width