Re: Display a public variable value in a text box....



Klatuu,

This sounds very interesting, and I would certainly like to have a look at it (at your convenience) if you don't mind!

Regards,
Nikos

Klatuu wrote:
Nikos,

I support your position on Public variables. There is another way to accomplish this that is more native to Access and avoids having to keep track of it at all. That is to create an application level property to hold the user name and load the value after the user has logged in. that way, it is always accessable. I use this in an application I have where the client wanted a security module other than Access. It creates two properties, UserName, and UserLevel, so I know what the user is allowed to do. Unfortunately, I don't have the code with me. It is at home. If you need it, post back and I can bring it in tomorrow.

"Nikos Yannacopoulos" wrote:


Gaba,

Public variables can only be referenced in code. To retrieve a public variable's value in a form, report, query etc you need to write a function to return its value, and call that from your form etc. For instance, assuming your public variable is called MyVariable, write a function in a general module like:

Function GetMyVariable()
GetMyVariable = MyVariable
End Function

Then you can call the function from anywhere in your project. So, to display its value in a textbox on a form, you would put this in the textbox's control source:

=GetMyVariable()

That said, that's all theory, but it's not good practice, simply because public variables are reset as soon as an untrapped error occurs in your code. Therefore it is safer to use controls on forms to store values, which do not suffer from this problem. In your particular case, you would go the other way around, i.e. once the user provides their username you store it directly in the textbox (or label) on the form (which, I undertand, remains open at all times anyway), and read it from there whenever required.
Generally, one can use hidden controls on a form to store values so they are not seen, or, in the absense of a switchboard or other form that remains open at all times, one can make a form just for the purpose, open it at startup and keep it open but hidden as long as the database is open.


HTH,
Nikos

gaba wrote:

Hello,
I'm working with a login form (it saves the username in a public variable after verifying password), after that the form is closed. I'm trying to display the public variable in a text box on the main menu, so when is always displaying which user had login...


Any ideas? any help will be greatly appreciated

gaba :)

.



Relevant Pages

  • Re: Display a public variable value in a text box....
    ... for a single post. ... "Nikos Yannacopoulos" wrote: ... >>>Public variables can only be referenced in code. ... Therefore it is safer to use controls on forms to store ...
    (microsoft.public.access.formscoding)
  • RE: Public variable named from field content
    ... store the variable name and value in a collection, ... calculations in the project and they represent default conditions. ... to assign values from the default table to public variables that could ... Looping through the recordset and using a SELECT CASE ...
    (microsoft.public.access.formscoding)
  • Re: Display a public variable value in a text box....
    ... Public variables can only be referenced in code. ... Therefore it is safer to use controls on forms to store ... gaba wrote: ... display the public variable in a text box on the main menu, ...
    (microsoft.public.access.formscoding)
  • Tracking Log In and Log Out Times of Users
    ... I need to tracking log in and log out time of users. ... My approach is to set up Public variable that store the [UserId], ... Also will setup Public variables for user info conflict is a multiuser ...
    (microsoft.public.access.formscoding)
  • Re: Display a public variable value in a text box....
    ... I support your position on Public variables. ... Therefore it is safer to use controls on forms to store ... >> display the public variable in a text box on the main menu, ...
    (microsoft.public.access.formscoding)

Loading