Solved

How do I check windows username against table of accepted users?

Posted on 2013-11-14
6
268 Views
Last Modified: 2013-11-14
I know how to extract the windows username using environ("USERNAME").

I would now like to validate the username against a list af accepted users (tbl_Users).

How can that be done?
0
Comment
Question by:LarsDyrby
  • 3
  • 2
6 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39648395
Try this:

Dim sUser as string
sUser =  environ("USERNAME"). 
IF DCount("*", "tbl_Users","UserName = '" & sUser & "'")  > 0 then
       msgbox "Validated!"
Else
      msgbox "Not validated!"
end if 

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 39648404
That said, this is generally a better option for Windows Usernames than the Environ function:
http://access.mvps.org/access/api/api0008.htm
0
 
LVL 10

Expert Comment

by:Anthony Berenguel
ID: 39648410
There are a few different ways of doing this. What are the fields in tbl_Users? Are all users in that table or only accepted ones?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:LarsDyrby
ID: 39648608
tbl_Users contains only the accepted users
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39648656
The code I posted should do the trick.

It uses "UserName" as the field where your usernames are stored.  You'll have to substitute that with whatever fieldname your database actually uses.  eg: if your field name is "SignOn", you'd revise the DCount to reflect that:

IF DCount("*", "tbl_Users","SignOn = '" & sUser & "'")  > 0 then
0
 

Author Comment

by:LarsDyrby
ID: 39648685
Thx to mbizup
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now