How to turn off or control warnings? (1 Viewer)

Everterra

Registered User.
Local time
Today, 11:15
Joined
Jan 12, 2015
Messages
16
How to control which messages to see when executing a macro?

I have a macro calling an update query but I need only see one message, the second one.

I want to turn off the warnings but I want to know the action will be done.

"You are about to update 2 row(s)."
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:15
Joined
Feb 19, 2013
Messages
16,634
I don't use macro's so not sure what to suggest. In VBA you would use docmd.setwarnings to turn messages on or off, but depends on what the message is, or to be more precise, what generated the message. It may be that you will end up turning off all messages rather than being able to be selective, or perhaps the first message is reporting an error in which case you would use error handling to manage it rather than turning messages on or off.

In vba you would use db.execute and then capture the recordsaffected value to say 'you have updated 2 records'
 

Everterra

Registered User.
Local time
Today, 11:15
Joined
Jan 12, 2015
Messages
16
Thanks.

So, I can transform the macro in VBA.

I want o execute an update query.

Can I use that "db.execute and then capture the recordsaffected value to say 'you have updated 2 records' "?

What it would be the code?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:15
Joined
Feb 19, 2013
Messages
16,634
to use recordsupdated you need to create a db object so your code would be

Code:
Private Sub btnUpdate_Click()
dim db as dao.database
 
    set db=currentdb
    db.execute("your sql string here", dbfailonerror)
    msgbox "You have updated " & db.recordsaffected & " records", vbOKonly
    set db=nothing
 
end sub
you don't need to use dbfailonerror, but if you do the error message is one created by the sql engine if an error occurs i.e. the one you would get if you created a query with errors (which shouldn't occur if you have built it correctly), or an error occurs such as losing connection with the back end during the update. It would be customary to do this as good coding practice so you can handle it in the code and not cause the user to drop into the coding window or for the db to fail and need to be restarted.
 

Everterra

Registered User.
Local time
Today, 11:15
Joined
Jan 12, 2015
Messages
16
I think the query don't have errors.

I just want to have something that tells me the action is running.

Should I put in that "your sql string here" this:

Code:
DoCmd.OpenQuery "RecibosT_QCriarRecibo", acViewNormal, acReadOnly

or this?

Code:
INSERT INTO RecibosT ( RecT_FluxoId )
SELECT RecibosT_Efeito.tbFlxId
FROM RecibosT_Efeito;
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:15
Joined
Feb 19, 2013
Messages
16,634
you can try

"RecibosT_QCriarRecibo"

but I always use

"INSERT INTO RecibosT ( RecT_FluxoId ) SELECT RecibosT_Efeito.tbFlxId FROM RecibosT_Efeito"
 

Everterra

Registered User.
Local time
Today, 11:15
Joined
Jan 12, 2015
Messages
16
Many thanks CJ_London.

Since I'm working in another task, I will try your code later.

I'll return later, too.
 

Users who are viewing this thread

Top Bottom