code to run when any report is opened

Happy YN

Registered User.
Local time
Today, 20:52
Joined
Jan 27, 2002
Messages
425
I have a toolbar I want displayed whenever a report is opened , and hidden when the report is closed
I have many reports. rather than put the code into each report is there nothing global that could read:

Whenever any report is opened
docmd.showtoolbar "TB" true
whenever all report are closed
docmd.showtoolbar"TB" false

Thanks
 
Rather than waste my time as well as yours by posting something like "I don't think there is a direct way" or "I don't know any way," I thought it might be easier to not say anything at all. Since you beg for a reply, I'll give you on.

I don't think there is a way. What's wrong with just placing that code on every report? It's not too much code and you could just copy and paste it to each report. Just curious on why this is needed. Maybe I could give some pointers to get rid of the reason you would need this.

Vassago
 
Rather than open each report and paste I thought it would be neater to have one code that does the job
That way I don't need to remember to add the code to future reports that are created
BUT if there is no other way then......
Thanks anyway
 
Function RptClose1()
On Error GoTo RptClose1_Err

Dim db As DATABASE, doc As Document, con As Container
Set db = CurrentDb()
Set con = db.Containers("Reports")

For Each doc In con.Documents

DoCmd.Close A_REPORT, doc.Name
DoCmd.ShowToolbar "Menu Bar", acToolbarYes
DoCmd.ShowToolbar "Custom 1", acToolbarNo
DoCmd.ShowToolbar "Database", acToolbarYes

Next
Set db = Nothing




RptClose1_Exit:
Exit Function

RptClose1_Err:
MsgBox Error$
Resume RptClose1_Exit

End Function
 
Thanks rich
Thats what I needed
Does this open & close the toolbar or do I need to create a function for opening & a similar one for closing?
Thanks again
 
You can have one function that takes in a true or false value.

If FALSE is passed then you run the code for opening a report and if TRUE is passed then you run the code for closing a report.

i.e. (using Rich's code)

Code:
Function RptOperation(booOperation As Boolean) 

    On Error GoTo RptOp_Err 

    Dim db As DATABASE, doc As Document, con As Container 
    Set db = CurrentDb() 
    Set con = db.Containers("Reports") 

    For Each doc In con.Documents 
        If booOperation = True Then
            With DoCmd
                .Close A_REPORT, doc.Name 
                .ShowToolbar "Menu Bar", acToolbarYes 
                .ShowToolbar "Custom 1", acToolbarNo 
                .ShowToolbar "Database", acToolbarYes 
            End With
        Else
            With DoCmd
                .Open A_REPORT, doc.Name 
                .ShowToolbar "Menu Bar", acToolbarNo 
                .ShowToolbar "Custom 1", acToolbarYes 
                .ShowToolbar "Database", acToolbarNo
            End With
        End If
    Next
 
    Set db = Nothing 

RptOp_Exit: 
    Exit Function 

RptOP_Err: 
    MsgBox Error$ 
    Resume RptOp_Exit 

End Function


Then just call it with

=RptOperation(0)

to open it

and

=RptOperation(-1)

to close it.
 
So where do I put this function? Surely not in each open event of a report, I wanted to avoid this?
 
The code I posted is Run from the close report button on the custom report toolbar.
The code I use to Open a report is much more involved since it uses api to hide all the garbage normally associated with reports
 
So Rich are you saying after all this that I can' have a code applying when any report is opened?:(
and how do you get to a button on a toolbar to put code behind it?
Thanks
 
I assume TB is a custom toolbar that you've created, simply add a command button to the bar, you have to create and use a macro to RunCode, simply get the macro to run the function
 
Thanks rich thats nice and clear but I notice you 'ignored' the first part of my last post?!
Is API too difficult for an amateur like me or could I dare ask for your code?
Thanks
 
You can have something open from every report..

But you're going to have to add something to each report that tells it to do that. Now, you can avoid duplicating that code by Mile-O-Phile's method. Put the code in a module somewhere else, and just call it from every report's Open/Close event. It's one line of code in each report, just like you'd put DoCmd.Maximize to make sure the report opens fully.

If you don't understand the terms being used, I'd submit that perhaps this is too complicated of a method. Your other option that I can think of is to create a switchboard to open all your reports from. Store the report names in a listbox/combobox and put in the "Run Report" button code to open your toolbar. Look here for more information:
http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=30505
http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=21922

Regards,
David R
 
Hi David & thanks for your interest
I read thru both the links. I already have a combobox in my report launcher form to preview/print reports working fine & I could set the open event from there but that would still entail adding the close event to each report unless I run it as a macro off the close button in the toolbar.
However I have some reports working off other forms and I wanted a neat solution to wrap the whole thing up
Lets see what else tuns up!!
Thanks again
Happy yn
 
Lets see if I've got this straight, you want access to change toolbars when closing your reports without you having to add code anywhere?
 
Sorry for delay in reply Rich
All the access toolbars are disabled (not shown) while my file runs.
I have one custom toolbar which I want to turn on i.e make visible when any report runs and turn off if all reports are closed
I am therefore looking for code to run when any report is opened rather than type the code into the open & close event of all reports -past & future. I could also include other things in the code e.g. maximize etc
Thanks again for your continued interest & assistance
 

Users who are viewing this thread

Back
Top Bottom