[AccessD] Change Reports Caption From Code

John Bartow john at winhaven.net
Tue Jul 12 21:52:44 CDT 2005


Ahhh, I can finally stop holding my breath! I threw my poor excuse of an
answer out there just to keep this thread alive, I had a feeling you had
this done in classes and I was just waiting for you to describe how you did
it. :o)

So your writing a book on it all! Can you feed some chapters out on it for
proof reading purposes or something?

John B.

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John W. Colby
Sent: Tuesday, July 12, 2005 8:01 PM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Change Reports Caption From Code

>You may wish to consider using OpenArgs.

In my framework I use a pair of classes for this purpose.  Openargs (in my
system) are in the format ArgName1=ArgValue1;ArgName2=ArgValue2;... With as
many arguments as the developer needs to pass in to the form.

clsOpenArg (singular) is a simple class with a name/value pair of variables
and properties to read them back out.  clsOpenArgs (plural) is the
"supervisor"  It is passed the openarg string by the form class.  It parses
the openargs and creates an instance of clsOpenArg for each openarg passed
in, saving each instance in a colOpenArgs using the argument name as the
key.

The nice thing about using a class pair like this is that the form (or
report) then has a place to go to retrieve the arguments in a consistent
manner.  You (the developer) no longer need to parse arguments inside any
form that has arguments passed it, just instantiate the supervisor
(clsOpenArgs (plural)) and pass in the openargs string (in OnOpen of the
form / report) and then just read out the argument values using variable
names that you know exist because you set them.

For example:

OpenArgs - FormCaption=MyForm;lblCompanyName=Colby
Consulting;...MoreArgs=MoreValues;

In the form or report header, you dim an instance of the supervisor class

Dim lclsOpenArgs As clsOpenArgs

In OnOpen you set up the class and pass in the openargs, then just reference
the arguments:


Private Sub Form_Open(Cancel As Integer)
    lclsOpenArgs = New clsOpenArgs
    With lclsOpenArgs
        .OpenArgs = Me.OpenArgs

...the .OpenArgs method accepts the openargs string and parses them, placing
them into OpenArg class instances, then placing those class instances in a
colOpenArgs keyed on the argument name.

        lblCompanyName.Caption = .Arg("lblCompanyName")
        Me.Caption = .Arg("FormCaption")
    End With
End Sub

As you can see, the form code then just reads the argument values out by
passing in the name of an OpenArg it expects to receive and does something
with that value.

You can have one or 40 openargs, and clsOpenArgs just parses them and gets
them ready to use.  The form can read the values out of the supervisor class
clsOpenArgs by name.  The form class can read the values out anywhere they
are needed, in any event or even in functions that do something complex.

Another trick I use is to have a method in clsOpenArgs that looks up the
argument names in the properties collection of the form.  If the name
matches a property, the property is set to the value of the argument.  This
allows me to open a generic form and setup things like AllowEdits,
AllowDeletes etc using arguments passed in to OpenArgs.  Not always useful,
but when I need to do something like this it is just automatic.

Classic class programming.

This code and more will be found in a book I am madly (but slowly) writing
to be available at a bookseller near you sometime next year.

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Josh McFarlane
Sent: Tuesday, July 12, 2005 6:53 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Change Reports Caption From Code


On 7/12/05, Bob Heygood <bheygood at abestsystems.com> wrote:
> Thanks to all who responded. The on open event is what I used. I thot 
> of it earlier, but thot twice about using a global variable. Not to 
> start another rant/discussion, but I feel this is a good example a 
> good use of a global.
> 
> I am creating 79 PDFs from code, which involves opening a report. The 
> neat news is that the reports caption property is what Acrobat uses 
> for the resulting file name. Hence my need to change the caption each 
> time I programmically open the report.
> 
> 
> thanks again.
> 
> bob

You may wish to consider using OpenArgs. When calling the report via code,
you can pass it arguments via the DoCmd.OpenReport, then with the OnOpen
code, change the caption of the current report. I do this with an form that
I use to determine date range (changes form caption to be the name of the
report it is called to open) and it works like a charm.

DoCmd.OpenReport ReportTest, acPreview,,,,"Report Caption"

Then in the on open handler:
Caption = OpenArgs

or something similar to fit your needs.
--
HTH
Josh McFarlane
"Peace cannot be kept by force. It can only be achieved by understanding."
-Albert Einstein
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list