Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

append query how many records where affected

I am running this append query

CurrentDb.Execute "AppendToTable1", dbFailOnError

How would i determine how many records where affected.
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Of course you can do anything you want with X ... display it in a Text Box, and so on.
You will also want to add some error trapping in case an error occurs with the Execute operation ... since you have dbFailOnError (good)
Here is a full example more or lessv


Public Function mFx()
On Error Goto mFx_Error:

Dim x as Long  ' optional
With CurrentDb
      .Execute "YourActionQueryName", dbFailOnError '
       ' x = .RecordsAffected   'returns the number of records processed by the action query ' optional
End With

mFx_Exit:
   Err.Clear
   ' other clean up here
   Exit Function
mFx_Error:

   ' error trap code here
   GoTo mFx_Exit

End Function

Don't forget the Dots ....
I prefer a different database object.  It is a bit faster -- less overhead.
DbEngine(0)(0).Execute "AppendToTable1", dbFailOnError
debug.print DbEngine(0)(0).RecordsAffected

Open in new window

Good luck measuring the speed difference with today's faster systems :-)
In theory, yes a tad faster.
I stayed with CurrentDB because that's what the OP was familiar with ... and the real question was how to use RecordsAffected ...
Avatar of vbnetcoder
vbnetcoder

ASKER

ty