Share via

Run multiple functions from one command button

Anonymous
2015-08-19T15:49:21+00:00

hey guys,

Right now I have a form that requires the user to press 4 different command buttons to run 4 different queries. Because all of them are Make-Table queries, it requires that the user not only press the button but also requires that they say yes to three different messages that are associated with it : 

"Are you sure you want to run this type of action query?"

"The existing table will be deleted before you run the query, do you want to continue anyway?"

"You are about to paste X rows into the table."

All 4 of these commands must be run before the report is viewed, or else the formatting is messed up and/or Access is unable to find the required data. 

Is there anyway that that 

(a) These can be combined into one button? (e.g. using a macro? I saw a "Run Macro" command as one of the miscellaneous commands available but am not sure what Macro i would run)

(b) Remove some or all of the error codes so that the user doesn't have to click yes three times for each command. 

I don't have very much knowledge of VBA, so the less code required the better. 

Thanks for any help!!

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

ScottGem 68,830 Reputation points Volunteer Moderator
2015-08-19T16:55:04+00:00

Using a macro there is an Open Query Action You can add as many of these actions as you need. There is also a Set Warning action. You would have that as your First action and set it to False, then have another as the last action and set it back to True.

The SetWarnings action suppresses the warning messages. 

You can use the equivalent VBA methods

DoCmd.SetWarnings False

DoCmd.OpenQuery "queryname"

repeat for each query

DoCmd.SetWarnings True

Or you can use the .Execute command which also suppresses the warnings.

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2015-08-19T15:57:40+00:00

    ciao HHMM_access,

    on click event of on cmd button only :

    dbengine(0)(0).execute "query1", dbfailonerror

    dbengine(0)(0).execute "query2", dbfailonerror

    dbengine(0)(0).execute "query3", dbfailonerror

    dbengine(0)(0).execute "query4", dbfailonerror

    this avoid also the messagges, which you could avoid setting setWarning.

    Ciao, Sandro.

    Was this answer helpful?

    0 comments No comments