By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Public Function dbLocal

P: n/a
I have a couple of questions regarding the use of the following function:

Public Function dbLocal(Optional ysnInitialize As Boolean = True) As DAO.
Database

1. Do I just replace all the instances of "Set db = CurrentDB()" in my app
with "Set db = dbLocal()" ? Or, do I make db a public variable and set it
only once? Typically, I might set that local db variable a dozen or more
times in my applications. I suspect the former is the proper method, but
would welcome confirmation of that.

2. "Optional ysnInitialize As Boolean = True" is a structure I am unfamiliar
with. It would seem that if it were always passed as true, it wouldn't need
to be an argument at all, nevermind an optional one. Please explain this.

Thanks,

Bill R

--
Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Message posted via http://www.accessmonster.com
Apr 26 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Br
ragtopcaddy via AccessMonster.com wrote:
I have a couple of questions regarding the use of the following
function:

Public Function dbLocal(Optional ysnInitialize As Boolean = True) As
DAO. Database

1. Do I just replace all the instances of "Set db = CurrentDB()" in
my app with "Set db = dbLocal()" ? Or, do I make db a public variable
and set it only once? Typically, I might set that local db variable a
dozen or more times in my applications. I suspect the former is the
proper method, but would welcome confirmation of that.
Why not just set it to CurrentDB() in each place you want to use it? I can't
see any real benefit in trying to do the above?? Perhaps we need to see the
full function to understand what you are trying to achieve?

I wouldn't use a global variable in any case.
2. "Optional ysnInitialize As Boolean = True" is a structure I am
unfamiliar with. It would seem that if it were always passed as true,
it wouldn't need to be an argument at all, nevermind an optional one.
Please explain this.


It means the parameter is optional and defaults to True. eg. If you don't
pass anything to your function ysnInitialize would return true.

regards,

Br@dley
Apr 26 '06 #2

P: n/a
"ragtopcaddy via AccessMonster.com" <u9289@uwe> wrote in
news:5f5c097be6968@uwe:
I have a couple of questions regarding the use of the following
function:

Public Function dbLocal(Optional ysnInitialize As Boolean = True)
As DAO. Database
This is my code, if I'm not mistaken.
1. Do I just replace all the instances of "Set db = CurrentDB()"
in my app with "Set db = dbLocal()" ? Or, do I make db a public
variable and set it only once? Typically, I might set that local
db variable a dozen or more times in my applications. I suspect
the former is the proper method, but would welcome confirmation of
that.
Since the function returns a cached reference to the currently
opened database (initialized by a call to CurrentDB() if necessary),
you use dbLocal in place of database variables.

Instead of:

Set db = CurrentDB()
Set rs = db.Openrecordset(...)

All you do is:

Set rs = dbLocal.Openrecordset(...)

That's the beauty of it. The function replaces all database
variables that were initialized to point to CurrentDB().
2. "Optional ysnInitialize As Boolean = True" is a structure I am
unfamiliar with. It would seem that if it were always passed as
true, it wouldn't need to be an argument at all, nevermind an
optional one. Please explain this.


Well, read the code! It shows you what it does. Setting that
argument to FALSE is the only way to get into the de-initialize the
cached variable.

Now, why you'd want to do that? It is the only way to fully clean up
the memory used by this variable. You might choose to call it that
way before closing your application, just to be sure everything gets
cleaned up.

One thought occurs to me, though -- you quoted only the declaration
of the function. I assume you do have the full code for it?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Apr 27 '06 #3

P: n/a
David,

Thanks for the response (and the function!). Yes, I do have the entire
function.

I am not an intuitive "code-thinker", so I sometimes have difficulty
understanding the functionality of the more obscure tricks of the trade. I
also have a healthy humility regarding my interpretations and always seek
confirmation of my understanding. But with every question I get answered, I
gain a better understanding of these things.

I have been developing in Access since the beginning of Access 2.0, but I had
never come across a function with an optional argument preset to a value.
Your explanation clarified the usage of it. It's brilliant.

So, on any "Quit" procs, I will insert the function dbLocal(False).

Thanks,

Bill

David W. Fenton wrote:
I have a couple of questions regarding the use of the following
function:

Public Function dbLocal(Optional ysnInitialize As Boolean = True)
As DAO. Database


This is my code, if I'm not mistaken.
1. Do I just replace all the instances of "Set db = CurrentDB()"
in my app with "Set db = dbLocal()" ? Or, do I make db a public
variable and set it only once? Typically, I might set that local
db variable a dozen or more times in my applications. I suspect
the former is the proper method, but would welcome confirmation of
that.


Since the function returns a cached reference to the currently
opened database (initialized by a call to CurrentDB() if necessary),
you use dbLocal in place of database variables.

Instead of:

Set db = CurrentDB()
Set rs = db.Openrecordset(...)

All you do is:

Set rs = dbLocal.Openrecordset(...)

That's the beauty of it. The function replaces all database
variables that were initialized to point to CurrentDB().
2. "Optional ysnInitialize As Boolean = True" is a structure I am
unfamiliar with. It would seem that if it were always passed as
true, it wouldn't need to be an argument at all, nevermind an
optional one. Please explain this.


Well, read the code! It shows you what it does. Setting that
argument to FALSE is the only way to get into the de-initialize the
cached variable.

Now, why you'd want to do that? It is the only way to fully clean up
the memory used by this variable. You might choose to call it that
way before closing your application, just to be sure everything gets
cleaned up.

One thought occurs to me, though -- you quoted only the declaration
of the function. I assume you do have the full code for it?


--
Bill Reed

"If you can't laugh at yourself, laugh at somebody else"

Message posted via http://www.accessmonster.com
Apr 27 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.