Grabbing the computer/user name?

NewShoes

Registered User.
Local time
Today, 09:09
Joined
Aug 1, 2009
Messages
223
Hey all,

I was wondering if it's possible for Access to ..ermm...access the login name or actual username of a user on a computer. I'm basically just wanting to display a "Welcome User...." message on my splashscreeen and/or menu.

Many thanks,

-NS
 
User name

Computer Name

If you don't care about that someone can change them (it isn't likely anyway) you can use the

Environ("username")

Environ("computername")

instead.
 
Thanks for the quick reply Bob! I understand all but how to actually make this display in a form. A nudge in the right direction would be great :)

-NS
 
Thanks for the quick reply Bob! I understand all but how to actually make this display in a form. A nudge in the right direction would be great :)

-NS

You can put a text box on the form and the control source set to

=Environ("username")

(making sure to use the equals sign)

You can format the text box to look like a label (in design view, go to the control click on it, select the format tab of the properties dialog and select FLAT for the SPECIAL EFFECT property. Set the Border property to TRANSPARENT and the backstyle to TRANSPARENT so the form shows through and there you go).
 
Actually, I just tried this now and I get a Name? error.

I have created a text box on my main from and set its control source to =Environ("username")

I'm not a networked computer at the min (at home) if that makes a difference? My system is Windows 7 and Access 2007.

Thanks,
-NS
 
Actually, I just tried this now and I get a Name? error.

I have created a text box on my main from and set its control source to =Environ("username")

I'm not a networked computer at the min (at home) if that makes a difference? My system is Windows 7 and Access 2007.

Thanks,
-NS

What is the name of the text box?
 
Oh, yes, on 2007 you might need a wrapper function.

Create a standard module and paste this into it and name the module itself basUtilities

Code:
Function gUser() As String
   gUser = VBA.Environ("username")
End Function

and then use this as the control source of the text box:

=gUser()
 
Humm, that doesn't seem to work either. The name of the text box is txtName.

Very strange!
 
Humm, that doesn't seem to work either. The name of the text box is txtName.

Very strange!

what doesn't work? I just tested the gUser in 2007 and it worked great. Did you put the function I posted in to a STANDARD MODULE (not a form or report module)?
 
Yeh, just a standard module. Very stange that it works for you and not for me! However, i've sorted it purely by chance by looking at the expression builder. If I use the control source:

=CurrentUser()

It works great!

Thanks for all your help,
-NS
 
Yeh, just a standard module. Very stange that it works for you and not for me! However, i've sorted it purely by chance by looking at the expression builder. If I use the control source:

=CurrentUser()

It works great!

Thanks for all your help,
-NS

You must be using the old mdb file format and using Access Security.
 
Not that I know of, the extension is .accdb and I havn't touched any security settings. Very strange.

Well, normally you'll find that using

=CurrentUser

will return ADMIN for each user instead of their user name.

So, you should really try to get mine to work. It will be much more reliable.
 
Well, normally you'll find that using

=CurrentUser

will return ADMIN for each user instead of their user name.

So, you should really try to get mine to work. It will be much more reliable.

lol funny you should mention that. The username on this comp is actually Admin, so it may not work after all! I will try and get your way working....I checked the module, should it be a normal module or a class module?
 
lol funny you should mention that. The username on this comp is actually Admin, so it may not work after all! I will try and get your way working....I checked the module, should it be a normal module or a class module?

Normal module
 

Users who are viewing this thread

Back
Top Bottom