473,408 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Public Function dbLocal

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
3 3028
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: WindAndWaves | last post by:
Hi everyone Why do you use the word public in a function, when the function is fully accessible without the word public in front of it. I read the help, but did not really get it. Cheers ...
4
by: MLH | last post by:
The following function declaration confuses me... Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef sReason As String) As Boolean I tried pasting it and its code into an...
3
by: Parintas Themis STE Kardias | last post by:
Hi How can i use public variables. These variables i wand to use in different places on a form (like a button) and are neccessery to write the type of variable like: Public VAR1, var2 as integer...
1
by: May | last post by:
greetings, i came across a function while browsing thru the net. This function is created in a component. what i am curious to know is, is this the correct way to create a function using: Public...
4
by: Chris | last post by:
Hello, I'm just getting started with VB and am new to the group, so please excuse what may seem to be a rudimentary question. I've been writing basic programs and have noticed that the...
3
by: Gladys | last post by:
Dear newsgroup - do not reply to this e-mail address. I have just created it to avoid getting spam to my real address. Reply to the newsgroup. I am watching them all now so please reply now. ...
0
by: Benjamin Lukner | last post by:
Hi! I'd like to dynamically call API functions from different DLLs, depending on what platform the program runs. Now I'm wondering what the most simple way may be (without meta code and compiler...
4
by: Bugs | last post by:
Hi, I wonder if anyone can help me out. I'm building a vb.net application that has a form with a panel that contains several other sub forms (as a collection of controls). What I'm wanting to...
7
by: blublu123 | last post by:
Hi all, I have a number of fields on various forms that need data validation. If fields are empty (null), the form should not save and close, and the cursor should go to the appropriate field. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.