Solved

VB environ

Posted on 2010-11-28
12
496 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Gazza83
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 45

Assisted Solution

by:patrickab
patrickab earned 166 total points
ID: 34227013
Try:

TextBox1.Text = Environ("Username")
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34227054
I would also suggest changing the .Locked property to true so that no one can change anything in that textbox....
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34227201
I think he wants Environ("ComputerName")
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34227325
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
 

Author Comment

by:Gazza83
ID: 34227327
Yeap would like to lock the cell down, have been experimenting with altering the existing code but no joy yet.

0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34227380
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
 
LVL 37

Assisted Solution

by:TommySzalapski
TommySzalapski earned 167 total points
ID: 34227382
Here is a working example. Is this what you are after?
userform.xls
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 167 total points
ID: 34228461
I think this is what you need ?

Sid
Sample.xls
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34228963
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
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34229901
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
 
LVL 45

Expert Comment

by:patrickab
ID: 34230321
It's always a problem interpreting the question... perhaps the asker will clarify matters.

Patrick
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34235195
Gazza83 - Thanks for the points - Patrick
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question