Solved

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

Posted on 2013-11-14
6
270 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

825 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