Storing Variables for later use.

You only need to store the primary key as static, in this case the UserName, to gain a unique reference to the current logged user.

Everything else should be calculated at database level so all referenced data is current at point of query, not current at point of log-in.

It's quite reasonable for a supervisor to expect an update of user security level to be reflected immediately rather than at next log-in.

Like I said, yes if the situation requires it. In all of my databases over 12 years I have never required that level of functionality. So, I will not include it unless it is necessary because it can have a major impact if you need to check a security level for each record of 200,000 records. I have had that situation before. I did not write the original code for the project and it was checking the security level for each record and it didn't need to. The users, once they were in the system, had a certain security level ALWAYS. So, I implemented the hidden form on it and it went from being slow as a snail to the speed of a small dog.

So, again - I would say that you may be correct - technically, but in general practice, it depends on what your database is, what it is doing, and if the users will have a static level or not. If their role/level is static, then there is no need to follow a certain path when it is not necessary. Function should dictate the methods used.
 
If their role/level is static, then there is no need to follow a certain path when it is not necessary. Function should dictate the methods used.

If the role/level is updateable by any user of the application then it is NOT static.

If you ever do get asked for real-time role functionality in your products, which in effect you are providing if your SecLevel data is updateable by any user, then you will quickly discard this approach.

It is just a matter of if/when it is asked of you.
 
If the role/level is updateable by any user of the application then it is NOT static.

If you ever do get asked for real-time role functionality in your products, which in effect you are providing if your SecLevel data is updateable by any user, then you will quickly discard this approach.

It is just a matter of if/when it is asked of you.

I already said, it depends on the needs of your program and if necessary I would use the other approach. But 12 years without needing it is a very long time.

Your responses keep reminding me of those who insist that certain rules be followed all of the time even when those rules do not apply to the situation at hand.
 
If you wanted to be even more correct (IMHO) you should create a custom object to manage the user info. I haven't tried it but I'm guessing you could reference in query parameter...
 
I already said, it depends on the needs of your program and if necessary I would use the other approach. But 12 years without needing it is a very long time.

Your responses keep reminding me of those who insist that certain rules be followed all of the time even when those rules do not apply to the situation at hand.

I'll give one more go to explain because you're not understanding my point.

If the purchaser of your app decides that the user should not have to log-out/in to update user status your app will fail. That is a design flaw because any user could reasonably ask for this functionality either as a fix or an extension.

You've been lucky that none of your customers have pointed it out thus far. If they did how much work is it going to take to change the reference to that hidden field?

Each time you code an app like this you are increasing the risk of being asked to fix it. Why not code all future apps to allow this functionality if required?

These are the considerations of extensibility which encourages a continous improvement of good design.
 
All of my apps are not "sold" apps. They are custom specific applications for the company I am working for. So, I think we'll have to leave it at "we are not in full agreement" and leave it at that.
 
If you wanted to be even more correct (IMHO) you should create a custom object to manage the user info. I haven't tried it but I'm guessing you could reference in query parameter...

Hi Ken,

Long time no speaky :eek:

I don't use Access much anymore but in .net you can use the SQLCacheDependancy.

This allows you to store an object in the cache but tie it to a table. If the table is updated then the object is removed from the cache and you can retrieve an updated version. It's pretty cool.
 
Hi Ken,

Long time no speaky :eek:

I don't use Access much anymore but in .net you can use the SQLCacheDependancy.

This allows you to store an object in the cache but tie it to a table. If the table is updated then the object is removed from the cache and you can retrieve an updated version. It's pretty cool.

Hum... Don't do .net but it seems like an interesting solution...

Was it you I used to chat with about hunting? I just bought a second hand crossbow to try out. :)
 
Not wanting to get into any preference debate (I never went to MVP school, I rather wonder what it's like :-s) and I've used both variables, local tables and form stored values over time - I did just want to address a couple of technical points raised in this thread.

To comment briefly first on the concept of what's logical - well that's surely dependent to an extent on the developer (individual).
I'm not a huge proponent for developing to assist the "next" developer to work on a project (it's never happened so far - and if it did then... well, they should be able to follow what's going on anyway if they've their wits about them).
But I do what I feel is logical. I like grouping objects where reasonable.
So a form reference is an option - but could be wrapped in a function call in the same module which performs other persisted value functionality.
(No doubt some will say "then why not use variables instead" - again it's personal choice and technical belief... which I'll come to now).

The issues I wanted to address were mainly raised by Bob - so I'll quote him from time to time if I may.


>> I would suggest NOT using a DLookup everytime you need it as that adds uncessessary overhead to the program

Yes - addressing a variable in memory is quicker than a read from disk (though it's going to be cached most likely anyway).
But assuming you stash these local persisted settings into a local table, then the DLookups aren't hurting the network and will perform very quickly (the domain functions perform excellently on local tables - people give them a bad rap but they blow recordsets away locally).


>> PUBLIC VARIABLES can lose their values at times in the program. They are volatile, and a hidden form is not.

Well this is a common statement. It really applies to any variable - though obviously we expect procedure scope variables to reset. Proc, module, public - it's all the same.

But the whole issue is dependent.
If you release MDBs (ACCDBs) in a retail version of Access to your users then yes - you expose them to the potential of unhandled errors and then ending code (and this resets the variables - not the error).
Of course if you use the runtime then boom - unhandled error and your application crashes. (How good an incentive is that for error handling to noobs? ;-)
However IMO if you release open MDBs, then unhandled errors and reset variables are the least of your worries. users poking around modules and design scares the... well it fills me with dread. ;-)
Consequently MDEs (ACCDEs) are the predominant released application form.
Errors raised in an MDE will not break - and hence will not reset variables and objects. MDEs are essentially robust little robots marching on regardless.


>> It [a public variable] has to be called from a wrapper function (you can't reference it directly)

That's true - but then if you do so by force of habit with form references, then your queries which do so need to have that parameter evaluated explicitly when opening that query into a recordset. A standard procedure for opening recordset is an easy solution - but it's a requirement.
Form references in queries are a fantastic piece of Access functionality. The expression service in general is far more involved, active and helpful than many give it credit for. But it is very much Access functionality.


>> the wrapper function is called for every single record

Well this could happen - but it would be unusual.
If you have a variable holding the current username (let's say mstrUserName) and a procedure which retrieves this
Public Function fGetUserName As String
fGetUserName = mstrUserName
End Function
and that is referenced in a query
SELECT * FROM TableName WHERE CreatedBy = fGetUserName()

That's perfectly common. And calls that function precisely once.
Suppose that same function calls more than one piece of information.
Public Function fGetUserCredential(pstrCredentialName as String) As String
fGetUserCredential= mstrUserCol(pstrCredentialName)
End Function
and so we query
SELECT * FROM TableName WHERE CreatedBy = fGetUserCredential("UserName")
then that function is called by the query (by the expression service) precisely once.

Only if you're passing a parameter which could vary by row will the function be called for each row.
SELECT * FROM TableName WHERE CreatedBy = fGetUserCredential(SomeFieldName)

This is typical of heaping overhead on queries filtered by a calculated column and is best avoided (though sometimes necessary without tweaking normalisation ;-).
But in this case I don't see why a field dependent parameter would be required.


So, all in all - you make your own choice of preference.
There are nuances - but no right and wrong.
(Don't get me wrong - I believe there are cases where a development choice is right and another wrong - but I don't see this as one of them).
i.e. it's unworthy of making rigid statements about one way or the other.

Cheers!
 
Personally, I use a hidden form which opens when the database opens and I store the username and security level in unbound text boxes on the form for referring to whenever I need.

Hi Bob,

Could you please explain how to set up the hidden form? I have created a logon form and the user selects a name from cboEmployee and when they click the Login button it takes them to the Switchboard form. What code do I need to add to get Access to store the cboEmployee selection and then put it into a text box on the hidden form for later use? (I believe that is what we are trying to achieve?)

Many thanks for your help

Stretch
 
FWIW
You can save data to the registry.
Example: sLogin is the User Name entered into a textbox.
You can save the value.
Code:
SaveSetting appname:="AppNameHere", section:="SectionNameHere", _
        Key:="Login", setting:=sLogin
Where AppNameHere" is a label you make up
Where SectionNameHere is Section Name
Where "Login" is the Key Name
Where sLogin is the variable (its value)

To read from the registry:
Code:
sLogin = GetSetting(appname:="AppNameHere", section:="SectionNameHere", _
        Key:="Login")
Now your Login value is always available (On your computer and or if ran on other computers its stored as well).

HTH
 

Users who are viewing this thread

Back
Top Bottom