home

Reports:Detecting Which Report is Currently Open

6/15/01 10:21:29 AM

One very handy feature is to detect which report is currently open. The code for doing this:

Dim strRep as string
strRep = Reports(0).Name

The reason I was wanting this code in effect was because I was designing a pop-up box which opened whenever the report was opened and gave the user the option to print, email, or close. I wanted this to work with all reports, not just one particular one. That is why I wanted this code.

I posted a newsgroup to microsoft.public.access.formscoding, here it is:

*********************************************************************************

From: Larry R Harrison Jr [larryh@appliedimage.com]
Subject: Detecting Which Report is Loaded and Having Command Button on a Form Work With It
Date: Thursday, June 14, 2001 1:33 PM

I use the following code to detect if a form is open:
**********************************************************************
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed
Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
**********************************************************************
It's saved in the module section with a name like "utility_functions."

What I am now trying to do is design a form which opens in conjunction with
each report in the database. This form would work as a pop-up box to ask the
user if they wish to email the report, print it, export it, or close. I know
what Visual Basic statements to put in the buttons to make them do their
particular functions, but the buttons on the form also need to detect which
report name is open and vary the visual basic according to that. I would say
it would place the name of the report in a variable DIMmed as a String.

I am guessing that the code above--modified in some manner--would be
involved. I am guessing it would be modified to say "acReport" rather than
"acForm," but beyond that there needs to be code in the command buttons
themselves to detect which report is open.

Any tips?

Larry
for tips with Access 97 visit my web site at
https://www.angelfire.com/az/larrytucaz/index.html
microsoft.public.access.formscoding

From: Mark Giannou [markgiannou@hotmail.com]
Subject: Re: Detecting Which Report is Loaded and Having Command Button on a Form Work With It
Date: Friday, June 15, 2001 2:31 AM

I use a multipick listbox that is populated with all of the reports from a
particular database.  Right next to it is a text box that displays which
reports I've selected using shift or click and the mouse pointer.  Both
boxes are on a form with several buttons, clear selection, preview, print,
export, or whatever app I choose to open to work with the report
post-generation.  It's not too hard to make and the great thing about it is
I can print to several different network printers (because you can have them
each point to a specific printer in their page setups), and I don't have to
worry about changing printers at all. If I'm printing 13 reports on a batch
of data they all just go to their proper locations as fast as the code will
allow.

From: Terry Kreft [terry.kreft@mps.co.uk]
Subject: Re: Detecting Which Report is Loaded and Having Command Button on a Form Work With It
Date: Friday, June 15, 2001 2:40 AM


What you are trying to do is slightly different to the purpose of the
function you show.

The function you show could be modified in the way you outline to work with
reports but, it's purpose would be  to tell you whether a specific report
was loaded, whereas you want to know which report is loaded, (it's like the
difference between asking "Are you here, Fred?" and "Who are you?")

To do what you want to do just check the Reports collection to see which
reports are loaded.

e.g.

dim loRep as Report

for each loRep in Reports
    Msgbox loRep.Name
Next

Alternatively, as I expect you are going to control the application so that
only one report is loaded at a time, you could just use

    Dim strRep as string
    strrep = Reports(0).Name

To get the name of the loaded report.