Solved

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

Posted on 2013-11-14
6
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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.

759 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