Adding a "re-run" button to an Access 2007 ribbon

D

dan.rei1

Hi,

I'm rather new to using VBA, which I want to use in Access to get a
ribbon button to cause the "active query" (which is a parameterized
query that gets input from the user) to "re-run", so that it will ask
the user for new input. (With Access 2003 this was easy: I just put
the "run" button on a toolbar, and pressed it whenever it was needed.
With Access 2007 it wasn't quite as easy to get the button to appear
on a ribbon, but now that I have place the button there, I don't know
how to make it re-run the "active query.") (To re-run a query in
Access 2007 one must close the query output window, then find the
query among hundreds of queries, then double-click the query in order
to run it again; just "making it active" and "pressing the re-run
button" will be so much simpler!)

Here is the XML I have placed in table USysRibbons in order to create
the button, on a new ribbon Tab.

I'm hoping someone here might be able to give me a hand, or point me
to a reference, that will identify the VBA or other commands that
could let me know if the "active" screen is a query, and, if a query,
tell me the name of the query, so that I could use the DoCmd.OpenQuery
to re-run the query. (Or, if this is a bad approach, steer me toward
a better approach.)

Thanks in advance.
 
D

dan.rei1

Oops: I forgot the XML that I used to make the new button:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/
customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="dbCustomTab" label="RK Custom Tab" visible="true">
<group id="grpReRun" label="ReRun">
<button id="cmdQueryRunQuery" label="Run"
imageMso="QueryRunQuery" size="large" onAction="Macro2_Dan" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
 
A

Anthos

In the code for the Ribbon (VBA Editor, create a new Module)

Public Sub Macro2_Dan (control as IRibbonControl)
On Error Resume Next
DoCmd.Close acQuery, "<query name>", acSaveNo
Docmd.OpenQuery("<query name>")
End Sub

This is the on action event for the button.
When it is clicked, it will Run this code, which closes the query and
re-opens it,
If the query is not already open, then it will resume the next
(opening the query)
 
A

Anthos

I apologise, I think I jumped into answer that question to soon and
didn't read the question properly.

have you tried
Application.Screen.ActiveDatasheet

I believe that returns the active table / query that is on the screen.

Someone please correct me if I am mistaken on this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top