Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Username

Status
Not open for further replies.

NNNNN

MIS
Dec 2, 2002
90
0
0
GB
Hi I have created a data access page in Microsoft Access

The page is based on a query which I would like to set the criteria to the current Windows logged in user

I tried using environ("username") I am told that VBA does not work in VB Script

How on earth Can I get it to work so that when a user opens the data page from internet explorer they can see only the records based on their user name and not the whole table with everyone else's records?


Any help would be VERY much appreciated


 
Greetings!

I've you're simply talking about the Windows login user ID, then you can grab it this way...

Code:
Dim objNetwork

Set objNetwork = CreateObject("WScript.Network")

MsgBox objNetwork.UserName

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
Thanks for your quick reply

Ithe code looks good, but I am not sure where exactly to put it

I hav eput it in the scripting editor in different places but get errors and I can see how to do this

Do I put objNetwork.UserName in the query critera?

Thanks again

 
If this is an ASP page you may need to do Server.CreateObject instead of just CreateObject.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks

Please excuse my ignorance

this is my first time for data access page

I pt the code in
MSMODCSC OnCLick

<SCRIPT language=vbscript event=onclick for=MSODSC>
<!--
Dim objNetworkSet objNetwork =Server.CreateObject("WScript.Network")
MsgBox objNetwork.UserName
-->
</SCRIPT>

The error is complaining aboutr this line <!--

I have removed it. cghanged it but no good

I am assuming that the code goes somewhere in the VBSCript and not in the the in VBA Function?

Thanks Again
 
Code:
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName
MsgBox strUserName

Your set is on the same line as your dim.
strUserName is a variable you can use.
Msgbox is just notifying you of the username it grabbed.
 
Hi

Well Ididn't get any errors but n o message either

If I use the following

msgbox("hi")
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName
MsgBox strUserName

I get a message saying Hi
nut no other message with username

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top