Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Delete ADODB Recordset

I am trying to delete an ADODB recordset. Here is the code that I am using...

strSelect = "SELECT *"
strFrom = "FROM tblVehicleDetails"
strWhere = "WHERE ((tblVehicleDetails.[Unit Number])=" & lngUnitNumber &
")"
strOrderBy = ";"

Set rst = RunQuery(strSelect, strFrom, strWhere, strOrderBy, True)

rst.Delete adAffectCurrent

rst.UpdateBatch
rst.Close
Set rst = Nothing

The runquery function works and returns a connected recordset. There is no
error when the code runs but the records are not deleted. I have no trouble
deleting the records manually in the databse. Any thoughts...

TIA

Jim Thomlinson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Delete ADODB Recordset

No worries. I figured it out... You need to delete each record in the
recordset individually, before you update the batch...

"Jim Thomlinson" wrote:

I am trying to delete an ADODB recordset. Here is the code that I am using...

strSelect = "SELECT *"
strFrom = "FROM tblVehicleDetails"
strWhere = "WHERE ((tblVehicleDetails.[Unit Number])=" & lngUnitNumber &
")"
strOrderBy = ";"

Set rst = RunQuery(strSelect, strFrom, strWhere, strOrderBy, True)

rst.Delete adAffectCurrent

rst.UpdateBatch
rst.Close
Set rst = Nothing

The runquery function works and returns a connected recordset. There is no
error when the code runs but the records are not deleted. I have no trouble
deleting the records manually in the databse. Any thoughts...

TIA

Jim Thomlinson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Delete ADODB Recordset

Your best bet would be to skip the recordset altogether and just run a
delete SQL directly on the database. There's no need for a recordset
here.

You can see how many records were deleted using

Connection.Execute [SQLStatement], [RecordsAffected], [Options]

"RecordsAffected" will now contain the number of records affected
(deleted, in this case)

EG:

Dim strSQL As String
Dim lngRecs As Long
strSQL = "UPDATE Titles SET Price = Price * 1.10" & _
" WHERE Type = 'Business'"
conPubs.Execute strSQL, lngRecs, adCmdText
Response.Write lngRecs & " records were updated."



Tim.

"Jim Thomlinson" wrote in
message ...
No worries. I figured it out... You need to delete each record in
the
recordset individually, before you update the batch...

"Jim Thomlinson" wrote:

I am trying to delete an ADODB recordset. Here is the code that I
am using...

strSelect = "SELECT *"
strFrom = "FROM tblVehicleDetails"
strWhere = "WHERE ((tblVehicleDetails.[Unit Number])=" &
lngUnitNumber &
")"
strOrderBy = ";"

Set rst = RunQuery(strSelect, strFrom, strWhere, strOrderBy,
True)

rst.Delete adAffectCurrent

rst.UpdateBatch
rst.Close
Set rst = Nothing

The runquery function works and returns a connected recordset.
There is no
error when the code runs but the records are not deleted. I have no
trouble
deleting the records manually in the databse. Any thoughts...

TIA

Jim Thomlinson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB Recordset Function Jim Thomlinson[_3_] Excel Programming 2 December 11th 04 01:31 AM
ADODB Recordset problem Stefen Percoco Excel Programming 2 July 26th 04 06:31 PM
0 with ADODB Recordset Stefen Percoco Excel Programming 1 July 8th 04 09:54 PM
adodb.recordset with excel nate axtell Excel Programming 14 June 11th 04 01:32 PM
ADODB Recordset Seth[_3_] Excel Programming 0 August 5th 03 02:15 PM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"