Solved

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

Posted on 2013-11-14
6
269 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

895 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