PC Review


Reply
Thread Tools Rate Thread

Delete, Append, Update Counts

 
 
tcb
Guest
Posts: n/a
 
      1st Nov 2006
1) I setwarnings false, run a bunch of delete and append queries,
setwarnings true. Can I capture the values: how many records were
deleted or appended?

2) When running an update query I'd also like a count of records
updated and list:

Name: "Smith" updated to "Johnson."
Status: 0 updated to 1

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmFuIFQuIERpbmg=?=
Guest
Posts: n/a
 
      1st Nov 2006
If you use the Execute method of the Database object, then you can retrieve
the number of Records / Rows affected using the RecordsAffected Property
after each Query execution.

In addition, you don't need to use SetWarnings with Execute as Execute is
processed silently without warnings. You can also trap the error using the
dbFailOnError option.

Check Access VB Help on the Execute method of the Database object.

--
HTH
Van T. Dinh
MVP (Access)


"tcb" wrote:

> 1) I setwarnings false, run a bunch of delete and append queries,
> setwarnings true. Can I capture the values: how many records were
> deleted or appended?
>
> 2) When running an update query I'd also like a count of records
> updated and list:
>
> Name: "Smith" updated to "Johnson."
> Status: 0 updated to 1
>
>

 
Reply With Quote
 
Pieter Wijnen
Guest
Posts: n/a
 
      1st Nov 2006
Not in a Macro, you can't

Public Function RunQuery(ByVal inSQL As String, Optional ByVal ODBCConnect
As String=VBA.vbNullString) As Long
Dim RQDb As DAO.Database
Dim RQQDef As DAO.QueryDef
Dim thQ As String
Dim oldErr As DAO.Error
Dim Parm As DAO.Parameter

On Local Error Resume Next

Set oldErr = DAO.Errors(0)
VBA.Err.Clear

Set RQDb = Access.CurrentDb()
Set RQQDef = RQDb.QueryDefs(inSQL)
If VBA.Err.Number <> 0 Then ' Temp Query
Set RQQDef = RQDb.CreateQueryDef(VBA.vbNullString)
With RQQDef
If VBA.Len(ODBCConnect) > 0 Then
.ReturnsRecords = False
.Connect = ODBCConnect
End If
.SQL = inSQL
End With
End If
VBA.Err.Clear
With RQQDef
If VBA.Len(ODBCConnect) = 0 Then
For Each Parm In .Parameters
Parm.Value = Access.Eval(Parm.Name) 'Assumes Parameters refer to
Forms Controls
Next
End If
VBA.Err.Clear
If VBA.Len(ODBCConnect) = 0 Then
.Execute DAO.dbSeeChanges + DAO.dbConsistent + DAO.dbFailOnError
Else
.Execute
End If
RunQuery = .RecordsAffected
End With
If ShowErr And VBA.Err.Number <> 0 Then
ODBCError
VBA.Err.Clear
Else
If VBA.Err.Number <> 0 Then
Debug.Print "[RunQuery]", inSQL
Debug.Print VBA.Err.Number, VBA.Err.Description
End If
If Not oldErr Is Nothing Then
VBA.Err.Raise oldErr.Number, oldErr.Source, oldErr.Description ' Keep
Error State
End If

End If
RQQDef.Close: Set RQQDef = Nothing
Set RQDb = Nothing

End Function

HTH

Pieter



"tcb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 1) I setwarnings false, run a bunch of delete and append queries,
> setwarnings true. Can I capture the values: how many records were
> deleted or appended?
>
> 2) When running an update query I'd also like a count of records
> updated and list:
>
> Name: "Smith" updated to "Johnson."
> Status: 0 updated to 1
>


--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 5415 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Append/Delete/Update Query MikeinPhoenix Microsoft Access Queries 5 28th Jul 2008 07:06 PM
append update delete query code question =?Utf-8?B?U2FsbHk=?= Microsoft Access Queries 2 10th Jun 2006 01:15 PM
obtain Update..Append..query result counts =?Utf-8?B?bnljZG9u?= Microsoft Access Queries 1 10th Apr 2006 08:37 PM
Update/Append AND Delete combination? Ida Microsoft Access Queries 2 16th Nov 2005 03:38 AM
help with delete, update & append queries... =?Utf-8?B?QnJvb2s=?= Microsoft Access Queries 4 4th Nov 2005 02:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:57 PM.