Capturing User Name from form field entry

vangogh228

Registered User.
Local time
Today, 04:21
Joined
Apr 19, 2002
Messages
302
In this db, the users select their name from a dropdown in an auto-open form, but with no password. I want to capture this value for use as the default value in a field on another form, but with the first form closed. I have seen the ENVIRON(Username) function referred to many times on here, but I need to capture the entered value, not the Windows or network login.

Is this possible without leaving the form open? I suppose I could just set its Visible to False when they enter their name, but I try not to have any more windows open than are necessary.

THANKS for your help!!
 
You either need to keep that form open or copy the value to a global variable (or to another form that will be remaining open).
 
"global variable?" That sounds promising, but I am not familiar with that functionality. I'll do some searching. What would the syntax of something like that look like?

SomeVariable = Me![Username]

Then close the form? Could it possibly be that easy?

Thanks again for your kind help.
 
Yes, that easy. You'd want to declare the variable as public in a standard module.
 
At the top of a module, put this (outside of any subs or functions).

Global SomeVariableName As VariableType
 
OK. I think I understand. It makes sense to me. Now, in the case that I have multiple users using this functionality at the same time, will the 'global' nature of this feature overwrite content from one user tothe next... or is it contained within each user's session like filtering forms, etc?

Thanks again, guys. This is a huge step forward for me!
 
Since you'll make sure each user has their own copy of the front end, not share a common copy, they won't conflict with each other.

Moniker, what happened to:

Moniker said:
I know this sounds cold and mean and otherwise uncaring, but we are here to answer questions, not give you fish, as it were.
 
pbaldy said:
Originally Posted by Moniker
I know this sounds cold and mean and otherwise uncaring, but we are here to answer questions, not give you fish, as it were.

lol...

I've told you I have a problem in that I want to provide a direct answer more often than not. I'm working on it.

Here I am taking my own medicine not all too long ago. ;)
 
Thanks for the help... but I need one more thing to finish this. This is what I have so far:

A module that reads:

Option Compare Database
Option Explicit
Global UserSignIn As String


A form field caled Emp_Name to accept the sign-in name, and a button on the form that has the following code:

Private Sub Command2_Click()

If IsNull(Me![Emp_Name]) Then
MsgBox "You must enter your name to continue.", vbOKOnly, "No Name Entered"
Else
UserSignIn = Emp_Name.Value
DoCmd.Close
End If

End Sub

I'll add an additional line to open the correct next form, that they use for input. In that input form, I want to use the UserSignIn value as a default value for the ServiceRep's name field. But, each time I go into the Default property and type in UserSignIn, Access puts quotes around it the default value says "UserSignIn" instead of the person's name that signed in.

Thanks again for all your help!!

--- --- ---

Got it !! Thanks again.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom