VB environ

Is is possible to replace the dropdown (Logged by) in the useform?

I was wondering if the computers username could be automatically displayed (Environ). It would just pick up the name of the PC as opposed to selecting a name in the dropdown.



userform.xls
Gazza83Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
SiddharthRoutConnect With a Mentor Commented:
I think this is what you need ?

Sid
Sample.xls
0
 
patrickabConnect With a Mentor Commented:
Try:

TextBox1.Text = Environ("Username")
0
 
SiddharthRoutCommented:
I would also suggest changing the .Locked property to true so that no one can change anything in that textbox....
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
TommySzalapskiCommented:
I think he wants Environ("ComputerName")
0
 
TommySzalapskiCommented:
For future reference, pull up a command prompt and type SET and it will give you a list of all the environment variables currently in the system. I use this a lot because I always forget what they are all called.
0
 
Gazza83Author Commented:
Yeap would like to lock the cell down, have been experimenting with altering the existing code but no joy yet.

0
 
TommySzalapskiCommented:
Lock what cell down? The textbox? Right click on it in the designer and hit properties and set Locked to true like Siddharth suggested. Also, if Environ doesn't work use VBA.Environ
To lock all the cells in the sheet just turn on protection. In the workbook_Open event do this
Private Sub Workbook_Open()
  Worksheets("Low Volume").Protect Password:="gary", UserInterfaceOnly:=True
End Sub

Open in new window

Then all the data will be protected from any changes except from within the code. Or you could protect the normal way (tools->protect sheet) and just unprotect and reprotect in the code.
0
 
TommySzalapskiConnect With a Mentor Commented:
Here is a working example. Is this what you are after?
userform.xls
0
 
patrickabCommented:
Tommy,

>I think he wants Environ("ComputerName")

As this would always be the same on any individual computer there would be little point in accessing it.

A password on the other hand would serve a purpose - probably.

Patrick
0
 
TommySzalapskiCommented:
Yeah, I realized that later. He said " It would just pick up the name of the PC" but then I saw the labels in the userform and decided he actually did want Username.
0
 
patrickabCommented:
It's always a problem interpreting the question... perhaps the asker will clarify matters.

Patrick
0
 
patrickabCommented:
Gazza83 - Thanks for the points - Patrick
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.