473,473 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Create 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 6317
te***********@gmail.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.comwrote:
tech.rawst...@gmail.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.openrecordset("select * 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!FullName

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.openrecordset(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!FullName

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" <PleaseNOOOsPAMmkal...@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.openrecordset(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!FullName

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
pleaseNOOSpamKal...@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
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...
3
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...
38
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...
18
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...
8
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...
5
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...
8
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...
5
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...
9
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...
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
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,...
1
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...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.