Using TempVar Variable

dugoneill

Registered User.
Local time
Today, 14:35
Joined
Apr 11, 2008
Messages
22
I am trying to be able to have the user log into the database by selecting there name from the list of Users, then saving the user name as a TempVar, and then showing this field as a text field on other forms.

I don't want the user to need to select there name each time they end up on the main form, so I have it set up so the default value is the TempVar.

This works for when the main form is opened again, but even though it shows the name in the combo box, going forward to other forms it doesn't retain the value.

Attached is a quickly put together sample - frm_SelectUser represents the main form, from there the command button opens the 2nd form and closes this form, the button on that form in turn closes it and reopens frm_SelectUser.

Thanks for any assistance.
 

Attachments

Last edited:
I haven't yet looked at your db but from what you've explained I think it would be a matter of setting the combo box's value to the tempVar on the Got Focus or Enter event of the form.
 
I am trying to be able to have the user log into the database by selecting there name from the list of Users, then saving the user name as a TempVar, and then showing this field as a text field on other forms.

I don't want the user to need to select there name each time they end up on the main form, so I have it set up so the default value is the TempVar.

This works for when the main form is opened again, but even though it shows the name in the combo box, going forward to other forms it doesn't retain the value.

Attached is a quickly put together sample - frm_SelectUser represents the main form, from there the command button opens the 2nd form and closes this form, the button on that form in turn closes it and reopens frm_SelectUser.

Thanks for any assistance.

going forward.... mean you want to show the user name on another form??? you can refer you TempVars variable anytime anywhere in your application.

I always declare my TempVars in the Autoexec macro on startup and get it populated with the UserName, PCNumber from user login form.
 
going forward.... mean you want to show the user name on another form??? you can refer you TempVars variable anytime anywhere in your application.

I always declare my TempVars in the Autoexec macro on startup and get it populated with the UserName, PCNumber from user login form.

Yes - I want to have a text field at the top of the forms showing the name of the person currently "logged in". It works to show the name on the top of the 2nd form, but if you then go back to the 1st form, and then back to the 2nd form again, it seems to cancel it out rather than retaining it.

I am not sure if it is just losing the tempVar or if it is being reset to blank when the main form is reopened.
 
I haven't yet looked at your db but from what you've explained I think it would be a matter of setting the combo box's value to the tempVar on the Got Focus or Enter event of the form.

Didn't work on the Got Focus, works once with the default setting, but if for some reason you cycle through the forms again without re-selecting a name in the combo box, it loses it.
 
Didn't work on the Got Focus, works once with the default setting, but if for some reason you cycle through the forms again without re-selecting a name in the combo box, it loses it.
Just had a look at your db. A TempVar is an overkill for what you want to do. A simple global variable and a function to return the value of the global variable would do. See attached.
 

Attachments

Just had a look at your db. A TempVar is an overkill for what you want to do. A simple global variable and a function to return the value of the global variable would do. See attached.

Much simpler approach, that is for sure - thanks!
Still not sure why the other wasn't working after cycling through, but this will definitely work instead.

So much to learn...don't even know where to start!!!
 
Yes - I want to have a text field at the top of the forms showing the name of the person currently "logged in". It works to show the name on the top of the 2nd form, but if you then go back to the 1st form, and then back to the 2nd form again, it seems to cancel it out rather than retaining it.

I am not sure if it is just losing the tempVar or if it is being reset to blank when the main form is reopened.

if you just want to show the name of a logged in user then no need for such a big work like declaring TempVars, creating function GetUserName.bla bla...


Just do the following:
  1. create a unbound textbox control on the desire form.
  2. just copy and paste the following in the data source control of the text box.
Code:
=[Forms]![frm_SelectUser]![cmbUserName].[column](1)
This will show the logged in user name where ever you want to show in your forms.

cheers
 
Much simpler approach, that is for sure - thanks!
Still not sure why the other wasn't working after cycling through, but this will definitely work instead.

So much to learn...don't even know where to start!!!
Not sure why the other wasn't working. It's been a long time since I used macros.

Glad that's working for you.
 
if you just want to show the name of a logged in user then no need for such a big work like declaring TempVars, creating function GetUserName.bla bla...


Just do the following:
  1. create a unbound textbox control on the desire form.
  2. just copy and paste the following in the data source control of the text box.
Code:
=[Forms]![frm_SelectUser]![cmbUserName].[column](1)
This will show the logged in user name where ever you want to show in your forms.

cheers

Thanks Khalid_Afridi, this apparently does need to be a little more complex than this though.

Trying this, it appears you still need a way to either requery or refresh the textbox (if someone different then uses it without reopening), also it only seems to work if the frm_SelectUser form stays open, which is not desired (want to close anything not being used to reduce clutter)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom