473,594 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a global constant at runtime

I have a function that retrieves a user's login name from their
workstation and looks it up on an employee table to return their full
name (ie: jsmith -John Smith). Their full name is then displayed on
each form as a greeting, while their login name is used to record
their activities, as well as compared to a list of positions that
allows different users to access different functions on the database.
I have noticed two things however:

a) on menu forms with no discernible data source, the name display
function works fine, but on pages that required users to move from one
record to another, the name display function is executed every time
another record is accessed, even though it has nothing to do with that
record. additionally, if a record does have a username that needs to
be displayed, it will take take longer for access to display the name
on the record and on the user's form.

b) if a user does not match the table with an elevated position, they
are not given certain options. however, if the program hits a glitch
or jumps out of the program flow, it will allow some options to be
shown, even though the user name does not match any names on the
elevated position tables. catching and recovering from the errors are
not impossible, but menu options appear regardless.

i know i have not provided any code, but i was wondering if anyone
knew where the problem might be originating from so i can zero in on
the code and inspect it further. currently, the display name function
is in a module that all the other pages can access, and the menu
options are on the forms that need to selectively display options,
usually in the manner of

if(gbl_empID = gbl_admin) then 'show appropriate options

any ides or comments?

Jun 1 '07 #1
5 6336
te***********@g mail.com wrote:
I have a function that retrieves a user's login name from their
workstation and looks it up on an employee table to return their full
name (ie: jsmith -John Smith). Their full name is then displayed on
each form as a greeting, while their login name is used to record
their activities, as well as compared to a list of positions that
allows different users to access different functions on the database.
I have noticed two things however:

a) on menu forms with no discernible data source, the name display
function works fine, but on pages that required users to move from one
record to another, the name display function is executed every time
another record is accessed, even though it has nothing to do with that
record. additionally, if a record does have a username that needs to
be displayed, it will take take longer for access to display the name
on the record and on the user's form.

b) if a user does not match the table with an elevated position, they
are not given certain options. however, if the program hits a glitch
or jumps out of the program flow, it will allow some options to be
shown, even though the user name does not match any names on the
elevated position tables. catching and recovering from the errors are
not impossible, but menu options appear regardless.

i know i have not provided any code, but i was wondering if anyone
knew where the problem might be originating from so i can zero in on
the code and inspect it further. currently, the display name function
is in a module that all the other pages can access, and the menu
options are on the forms that need to selectively display options,
usually in the manner of

if(gbl_empID = gbl_admin) then 'show appropriate options

any ides or comments?
Look at http://www.mvps.org/access/api/api0008.htm
And http://www.mvps.org/access/api/api0066.htm

You could create a table. Call it WhoAmI (assumes split database).
When you enter the system store the info in WhoAmI. It would always be
the first (and only record) in the table. Then call Dlookup to get the
name and login when necessary. Should be quick in a 1 record table.

Jun 1 '07 #2
On Jun 1, 5:45 pm, salad <o...@vinegar.c omwrote:
tech.rawst...@g mail.com wrote:
I have a function that retrieves a user's login name from their
workstation and looks it up on an employee table to return their full
name (ie: jsmith -John Smith). Their full name is then displayed on
each form as a greeting, while their login name is used to record
their activities, as well as compared to a list of positions that
allows different users to access different functions on the database.
I have noticed two things however:
a) on menu forms with no discernible data source, the name display
function works fine, but on pages that required users to move from one
record to another, the name display function is executed every time
another record is accessed, even though it has nothing to do with that
record. additionally, if a record does have a username that needs to
be displayed, it will take take longer for access to display the name
on the record and on the user's form.
b) if a user does not match the table with an elevated position, they
are not given certain options. however, if the program hits a glitch
or jumps out of the program flow, it will allow some options to be
shown, even though the user name does not match any names on the
elevated position tables. catching and recovering from the errors are
not impossible, but menu options appear regardless.
i know i have not provided any code, but i was wondering if anyone
knew where the problem might be originating from so i can zero in on
the code and inspect it further. currently, the display name function
is in a module that all the other pages can access, and the menu
options are on the forms that need to selectively display options,
usually in the manner of
if(gbl_empID = gbl_admin) then 'show appropriate options
any ides or comments?

Look athttp://www.mvps.org/access/api/api0008.htm
Andhttp://www.mvps.org/access/api/api0066.htm

You could create a table. Call it WhoAmI (assumes split database).
When you enter the system store the info in WhoAmI. It would always be
the first (and only record) in the table. Then call Dlookup to get the
name and login when necessary. Should be quick in a 1 record table.
I think i used the first one, if not a variation of it. the second
one is a bit too intricate thought. Still, I think your "WhoAmI" idea
is simple enough to try. also, while trying out the other getname
function, i noticed that the display user name function (either mine
or the one you linked to) was executed each time a record was accessed
that needed to look up extraneous data, such as a form that has a
datasource defined, but also has to retrieve data from another table.
I've tried making queries to centralize all the data i need for a
form, but certain forms need different external data according to the
selections made on the form.

Jun 1 '07 #3
the name display function is executed every time
another record is accessed, even though it has nothing to do with that
record.
Gee, you could put your function that displays this infofaton in the fomrs
footer, it might not execute everytime. However, why is exetin this fucitno
goign to be a problem.

ms-access is able to run 10, or 20 millin instricons per seocnd. I can't
imainge that you worred aobut saving 1 millioned of a second? Why would you
waste such developer resouces on this small thiing?

Lets try a some code to see how fast that lookup occures:

dim gblRstUser as dao.recordset
Call setuser()
....this rouitne will setup the user table
dim strSql as string

set strSql = "select * from tblUsers where UserName = '" & strLogOn & "'"
set glRstUser = currentdb.openr ecordset("selec t * from tblUsers where
UserName =

So, now we have a glboal record that is set to the users name.

Our function to retive teh "full name" wold be

Public Function UFullName() as string

UFullName = gblRstuser!Full Name

end function.

So, on our rerpots, we go:

=UFullname().

lets test how much time it takes to execute our fucntion to lookup and
retive taht full name.
dim i as long
dim t as double
dim s as string
t = timer
for i = to to 1000000
s = UfullName()
next i

t = timer - t
debug.print t

debug.pritn = 2.7 seconds

So, we can exeute this grabbing of the users full naem 1 million times in
2.7 seconds (that on my weaker notebook). So, the time to exectue thsi
fuction ONCE on your form is:
2.7 / 1000000 = 0.0000027

That is not even 100,000 of a second.

Or, simply put, ms-access can execute that function 370,000 times PER
SECOND.

So, if you used the navagtion arrows to view and move throught 370,000
reocrds, the increase time to view those records would be 1 adtional
seconds. And, if a uers was clciking the next buttion once per second, it
would take 6000 seconds (102 minutes) to view that many rerocrs. 102 minutes
is nearing two hours, and in that period you going to increate tihs time by
ONE SECOND.

Really, is there somting paritlcar in your world that you really need to
save 1 second over seveal hours of time?

I must be compliery and 100% missign your point, but some werid and
unforness deatil is being left out here....
additionally, if a record does have a username that needs to
be displayed, it will take take longer for access to display the name
on the record and on the user's form.
Are you talking about a user logon name that you get once at startup (when
the user logson), or a user name that is a actual field on the form? (and
you looking up this value?). If you need high speed looikup for a form,
consider using a left join, and include that users table (but, it not 100%
clear here, becuase in the prevous parrage you talking about a users logon,
and not you seem to be talking about data in the form.

however, once again, perfoamcne should be a noticalbe issue here.
b) if a user does not match the table with an elevated position, they
are not given certain options. however, if the program hits a glitch
or jumps out of the program flow, it will allow some options to be
shown, even though the user name does not match any names on the
elevated position tables. catching and recovering from the errors are
not impossible, but menu options appear regardless.
Huh? you complte lost me in the above. If you don't trap errors in
sma-ccess,
then ALL LOCAL AND GLOBAL varables are re-set, and their values are lost.

Solution:
a) use error hadning code
b) displiate a mde to your users. Unhandeld errors will NOT re-set
vaiblaes
There is zillion reasons to displaite a mde to your end usrs, and any
devloper
worht their salt will immdmdiyy reialzing this.

It not clear what you mean by "glitch", you might want ot expain furhter.
>
if(gbl_empID = gbl_admin) then 'show appropriate options

any ides or comments?
Well, all I can say is once you got the users logon name, then load in the
reocrdset (or as my example shows, set the global reocrdset to the ONE
record...and you can retrieve values from that one record easily in excess
of 250,000 values per second. You not give any details as to if you doing
some type of table scan to retrieve values from "MANY" records to grab your
information used for privileges, or if you use one record with many fields.
If you do actually have multiple records for each logon user that holds the
permissions, then simply load up the reocrdset at logon with users 15, or 20
records....a findfirst on that table will be super fast, and again I can't
see reason to worry about performance issues..
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
Jun 1 '07 #4
Yikes...lets try this will spell checking....
the name display function is executed every time
another record is accessed, even though it has nothing to do with that
record.
Gee, you could put your function that displays this information in the forms
footer, it might not execute every time. However, why is executing this
function
going to be a problem.

ms-access is able to run 10, or 20 million instructions per second. I can't
imagine that you worried about saving 1 millioned of a second? Why would you
waste such developer resources on this small thing?

Lets try a some code to see how fast that lookup occures:

dim gblRstUser as dao.recordset
Call setuser()
....this rouitne will setup the user table

eg:
dim strSql as string

set strSql = "select * from tblUsers where UserName = '" & strLogOn & "'"
set glRstUser = currentdb.openr ecordset(strSql )

So, now we have a global record that is set to the users name.

Our function to retrieve the "full name" would be

Public Function UFullName() as string

UFullName = gblRstuser!Full Name

end function.

So, on our rerpots, we go:

=UFullname().

lets test how much time it takes to execute our function to lookup and
retrieve that full name.
dim i as long
dim t as double
dim s as string
t = timer
for i = to to 1000000
s = UfullName()
next i

t = timer - t
debug.print t

debug.pritn = 2.7 seconds

So, we can execute this grabbing of the users full name 1 million times in
2.7 seconds (that on my weaker notebook). So, the time to execute this
function ONCE on your form is:
2.7 / 1000000 = 0.0000027

That is not even 100,000 of a second.

Or, simply put, ms-access can execute that function 370,000 times PER
SECOND.

So, if you used the navigation arrows to view and move through 370,000
records, the increase time to view those records would be 1 additional
seconds. And, if a users was clicking the next button once per second, it
would take 6000 seconds (102 minutes) to view that many records. 102 minutes
is nearing two hours, and in that period you going to increate this time by
ONE SECOND.

Really, is there something particular in your world that you really need to
save 1 second over several hours of time?

I must be complete and 100% missing your point, but some weird and
unforeseen detail is being left out here....
additionally, if a record does have a username that needs to
be displayed, it will take take longer for access to display the name
on the record and on the user's form.
Are you talking about a user logon name that you get once at start-up (when
the user logon), or a user name that is a actual field on the form? (and
you looking up this value?). If you need high speed lookup for a form,
consider using a left join, and include that users table (but, it not 100%
clear here, because in the previous paragraph you talking about a users
logon,
and not you seem to be talking about data in the form.

however, once again, performance should be a not be noticeable issue here.
b) if a user does not match the table with an elevated position, they
are not given certain options. however, if the program hits a glitch
or jumps out of the program flow, it will allow some options to be
shown, even though the user name does not match any names on the
elevated position tables. catching and recovering from the errors are
not impossible, but menu options appear regardless.
Huh? you complete lost me in the above. If you don't trap errors in
ms-access,
then ALL LOCAL AND GLOBAL variables are re-set, and their values are lost.

Solution:
a) use error handing code
b) distribute a mde to your users. Unhandled errors will NOT re-set
variables
There is zillion reasons to distribute a mde to your end users, and any
developer
worth their salt will realize this.

It not clear what you mean by "glitch", you might want to explain further.
>
if(gbl_empID = gbl_admin) then 'show appropriate options

any ides or comments?
Well, all I can say is once you got the users logon name, then load in the
reocrdset (or as my example shows, set the global reocrdset to the ONE
record...and you can retrieve values from that one record easily in excess
of 250,000 values per second. You not give any details as to if you doing
some type of table scan to retrieve values from "MANY" records to grab your
information used for privileges, or if you use one record with many fields.
If you do actually have multiple records for each logon user that holds the
permissions, then simply load up the reocrdset at logon with users 15, or 20
records....a findfirst on that table will be super fast, and again I can't
see reason to worry about performance issues..

Note that you can declare variables as public in a standard module, and they
are available anywhere, and anytime. If you need a variable as a expression,
then you have to sue a function as above.

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com

Jun 1 '07 #5
On Jun 1, 7:38 pm, "Albert D. Kallal" <PleaseNOOOsPAM mkal...@msn.com >
wrote:
Yikes...lets try this will spell checking....
the name display function is executed every time
another record is accessed, even though it has nothing to do with that
record.

Gee, you could put your function that displays this information in the forms
footer, it might not execute every time. However, why is executing this
function
going to be a problem.

ms-access is able to run 10, or 20 million instructions per second. I can't
imagine that you worried about saving 1 millioned of a second? Why would you
waste such developer resources on this small thing?

Lets try a some code to see how fast that lookup occures:

dim gblRstUser as dao.recordset

Call setuser()
...this rouitne will setup the user table

eg:
dim strSql as string

set strSql = "select * from tblUsers where UserName = '" & strLogOn & "'"
set glRstUser = currentdb.openr ecordset(strSql )

So, now we have a global record that is set to the users name.

Our function to retrieve the "full name" would be

Public Function UFullName() as string

UFullName = gblRstuser!Full Name

end function.

So, on our rerpots, we go:

=UFullname().

lets test how much time it takes to execute our function to lookup and
retrieve that full name.

dim i as long
dim t as double
dim s as string
t = timer
for i = to to 1000000
s = UfullName()
next i

t = timer - t
debug.print t

debug.pritn = 2.7 seconds

So, we can execute this grabbing of the users full name 1 million times in
2.7 seconds (that on my weaker notebook). So, the time to execute this
function ONCE on your form is:

2.7 / 1000000 = 0.0000027

That is not even 100,000 of a second.

Or, simply put, ms-access can execute that function 370,000 times PER
SECOND.

So, if you used the navigation arrows to view and move through 370,000
records, the increase time to view those records would be 1 additional
seconds. And, if a users was clicking the next button once per second, it
would take 6000 seconds (102 minutes) to view that many records. 102 minutes
is nearing two hours, and in that period you going to increate this time by
ONE SECOND.

Really, is there something particular in your world that you really need to
save 1 second over several hours of time?

I must be complete and 100% missing your point, but some weird and
unforeseen detail is being left out here....
additionally, if a record does have a username that needs to
be displayed, it will take take longer for access to display the name
on the record and on the user's form.

Are you talking about a user logon name that you get once at start-up (when
the user logon), or a user name that is a actual field on the form? (and
you looking up this value?). If you need high speed lookup for a form,
consider using a left join, and include that users table (but, it not 100%
clear here, because in the previous paragraph you talking about a users
logon,
and not you seem to be talking about data in the form.

however, once again, performance should be a not be noticeable issue here.
b) if a user does not match the table with an elevated position, they
are not given certain options. however, if the program hits a glitch
or jumps out of the program flow, it will allow some options to be
shown, even though the user name does not match any names on the
elevated position tables. catching and recovering from the errors are
not impossible, but menu options appear regardless.

Huh? you complete lost me in the above. If you don't trap errors in
ms-access,
then ALL LOCAL AND GLOBAL variables are re-set, and their values are lost.

Solution:
a) use error handing code
b) distribute a mde to your users. Unhandled errors will NOT re-set
variables
There is zillion reasons to distribute a mde to your end users, and any
developer
worth their salt will realize this.

It not clear what you mean by "glitch", you might want to explain further.
if(gbl_empID = gbl_admin) then 'show appropriate options
any ides or comments?

Well, all I can say is once you got the users logon name, then load in the
reocrdset (or as my example shows, set the global reocrdset to the ONE
record...and you can retrieve values from that one record easily in excess
of 250,000 values per second. You not give any details as to if you doing
some type of table scan to retrieve values from "MANY" records to grab your
information used for privileges, or if you use one record with many fields.
If you do actually have multiple records for each logon user that holds the
permissions, then simply load up the reocrdset at logon with users 15, or 20
records....a findfirst on that table will be super fast, and again I can't
see reason to worry about performance issues..

Note that you can declare variables as public in a standard module, and they
are available anywhere, and anytime. If you need a variable as a expression,
then you have to sue a function as above.

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKa l...@msn.com
as cryptic and condescending as your reply is, i have to admit you
make a point. unfortunately, the person named "salad" explained in a
much more comprehensible and succinct manner. while i do appreciate
your lengthy and descriptive thesis on the amount of functions that
can be executed running off of an albeit slower notebook, i just
wanted some feedback on how I could do something better. for further
reference, it's not how well you can prove your answer to be correct -
it's how well your answer can be understood. remember, quality over
quantity.

Jun 2 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
4461
by: 2obvious | last post by:
I've been trying to create read-only global variables by creating constants (Const) in my global.asa, but I can't seem to reference them. Sticking them in an include works fine, but it seems more structurally sound to use Application_OnStart. Am I attempting the impossible, and if so, why?
3
8098
by: Dalan | last post by:
I need some assistance or advise in composing code for a global function module or a related one for populating values in text boxes on reports and forms with a name, actually several different names. There are over 50 fields in the database requiring name updates and I need to do this several times. And I don't want to use a table/form to perform this task. Here is a bit more information. Yes, I have done the changing of the values in...
38
2272
by: MLH | last post by:
I have 2 global constants declared in the same global module: Global Const MY_VERSION$ = "1.04" Global Const ProjectName$ = "MyProj" I have 2 global procedures designed to return the value of these 2 constants... Function GetCurrentRev() As String GetCurrentRev = MY_VERSION$ End Function
18
8631
by: vib | last post by:
Hi there, By chance, I came to learn that it is bad programming practice to initialize global variables at outside of programs. Is it that bad? In order to fullfil this, I had to declare them with const, but thereafter they are no longer variables. Just couldn't see the benefits of this practice. Any comments or advices are welcome. Thanks vib
8
2877
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger class that I want its instance to be accessible from any other classe in the project. There is also a bunch of constants that I want to be public for the
5
1901
by: Praveen | last post by:
I have script files embedded as resources in my dll. During runtime, I would like to write it out into the app dir (or a app sub-dir) and send the appropriate virtual path to the client. This makes deploying my dll much easier - just a single dll, not having to worry about deploying script files. However, the runtime doesn't seem have enough permissions to write out to the app dir (or any of it's subdir), by default. The folder where I...
8
5671
by: Thomas Coleman | last post by:
Ok, I've obviously discovered that Global.aspx has been completely changed in ..NET 2.0. However, I haven't figured out how to declare a constant that's available to any page in my application without having to jump through a bunch of hoops. First, let me layout how it worked in 1.1. In the Global.asax, within the Global class construct, I would simply add something like: public const string FOO = "foo";
5
2249
by: viveklinux | last post by:
Hi , writing a small application in C which has to create an XML document by reading a binary format file. Trying to get the indentation right by using a depth global variable which will insert appropriate number of tab spaces depending up on the depth. Is there any way that this can be done using a macro. So , something like
9
3319
by: Tony Proctor | last post by:
I need to create a process Singleton object for an ASP application, but I'm having some odd issues In my GLOBAL.ASA, I have an <OBJECTelement specifying the relevant ProgID with RUNAT=Server and SCOPE=Application However, although this works fine for some classes, I get a permission denied error for classes from a particular DLL. The error response is:- Active Server Pages error '8002802b'
0
7946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8253
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8009
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6661
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5411
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.