Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 6th, 2006, 11:17 AM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jscrogg
Default Deleting multiple records from the same table

I'm trying to delete multiple records in a table with the following code:

'Delete the record from the 'tblUGDate' table
    rstUGDate.CursorType = adOpenDynamic
    rstUGDate.LockType = adLockOptimistic
    rstUGDate.Open "SELECT * FROM tblUGDate WHERE [ID] = '" & txbID & "'", CurConn, , , adCmdText
    With rstUGDate
        .Delete
    End With
    rstUGDate.Close

The code is good for finding one record with the ID, it then deletes it and quits.

I want to delete all of the records that have the same ID.

Thanks
Jeremy
 
Old June 6th, 2006, 03:54 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use a delete statement, or you can loop through all records returned from your select statement, deleting each as you go.

Method 1 - delete statement
Code:
CurrConn.Execute("Delete From tblUGDate Where [ID] = '" & txbID & "'")
Method 2 - Loop through recordset
Code:
do while not rstUGDate.eof
  rstUGDate.Delete
  rstUGDate.MoveNext
loop
Have fun

Woody Z http://www.learntoprogramnow.com
 
Old June 7th, 2006, 01:58 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jscrogg
Default

Thanks a lot
 
Old June 12th, 2006, 05:30 AM
Authorized User
 
Join Date: Aug 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1. You can use delete Query
2. You can use movenext statements with in the with statements

Regards
Adalarasu. S
Xyka Software Pvt ltd, Bangalore






Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting all the records in a table suthaharmca Beginning VB 6 4 January 2nd, 2008 06:14 PM
Problem deleting records from a table ghall202 Access 4 March 2nd, 2007 03:58 PM
multiple records in a table fadege Classic ASP Databases 0 October 13th, 2005 07:40 AM
Insert multiple records in a Inner Join Table rylemer Access 1 August 22nd, 2004 07:44 AM
How Can I Delete Multiple Records From a Table? Lucy SQL Server 2000 5 May 12th, 2004 05:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.