Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here




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

RE: Username


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


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

RE: Username

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

RE: Username

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

"... 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

RE: Username


Please excuse my ignorance

this is my first time for data access page

I pt the code in

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

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

RE: Username


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.

RE: Username


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

If I use the following

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

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


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close