You are about to update xx rows (1 Viewer)

David44Coder

Member
Local time
Tomorrow, 07:29
Joined
May 20, 2022
Messages
109
When this is generated can you know if advance if the number of rows is 0 and thus turn off Warnings Off?
And the error message about being cancelled.
 

June7

AWF VIP
Local time
Today, 11:29
Joined
Mar 9, 2014
Messages
5,465
Exactly how are you running update action?

In VBA can use CurrentDb.Execute and won't get warnings.
 

David44Coder

Member
Local time
Tomorrow, 07:29
Joined
May 20, 2022
Messages
109
DoCmd.RunSQL sql
I liked the warnings when the number was > 0. Can you know that anyhow ?
 

June7

AWF VIP
Local time
Today, 11:29
Joined
Mar 9, 2014
Messages
5,465
Options:

1. possibly use DCount()

2. open a recordset and check its recordcount
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:29
Joined
Feb 19, 2013
Messages
16,606
Do you want to know the number before as a warning? or after as a report? If the latter you can use .execute rather than runsql

Code:
dim db as currentdb
db.execute sql
if db.recordsaffected<>0 then msgbox db.recordsaffected & " records affected"

the potential problem with getting the number before is it may not happen as the action query may not be able to update/append/delete all the records due to key or other violations
 

Isaac

Lifelong Learner
Local time
Today, 12:29
Joined
Mar 14, 2017
Messages
8,774
@CJ_London wait can you really do that?? Declare "db" as...and then use the word that should be in the Set command? If so I never knew.

Or did you mean

dim db as dao.database
set db=currentdb
db.execute......

(Not intending to be picky, just wondering if I'd missed a cool functionality)
 

Isaac

Lifelong Learner
Local time
Today, 12:29
Joined
Mar 14, 2017
Messages
8,774
@David44Coder
If you're using SQL Server as a back end or any other RDBMS that supports intricate transaction-related coding, you could leverage that to solve the problem.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:29
Joined
Feb 19, 2013
Messages
16,606
My mistake , you are of course correct.
 

Isaac

Lifelong Learner
Local time
Today, 12:29
Joined
Mar 14, 2017
Messages
8,774
It looks so much like the manner in which a SQL server variable can be instantiated + set that I wasn't sure. Thanks.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 15:29
Joined
Apr 27, 2015
Messages
6,319
@CJ_London wait can you really do that?? Declare "db" as...and then use the word that should be in the Set command? If so I never knew.
One habit I have developed, simply because I think it looks cleaner:

Dim db as DAO.Database : Set db = CurrentDb
 

David44Coder

Member
Local time
Tomorrow, 07:29
Joined
May 20, 2022
Messages
109
Thanks for the ideas. Yes Junes plan would work fine but I liked CJs and had never come across .recordsaffected so used that.
I've error trapping so will see if a cannot update condition needs any changes.
Now I have what must be a silly question. Why use Set at all?
CurrentDb.Execute sql
Right or wrong, eliminating an instruction feels more efficient and no need to Set = Nothing. But I might be missing something.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 15:29
Joined
Apr 27, 2015
Messages
6,319
Thanks for the ideas. Yes Junes plan would work fine but I liked CJs and had never come across .recordsaffected so used that.
I've error trapping so will see if a cannot update condition needs any changes.
Now I have what must be a silly question. Why use Set at all?
CurrentDb.Execute sql
Right or wrong, eliminating an instruction feels more efficient and no need to Set = Nothing. But I might be missing something.
Have a read https://social.msdn.microsoft.com/F...et-a-database-object-variable?forum=accessdev
 

Users who are viewing this thread

Top Bottom