0

My database opens to a specific form on start up and it checks the user name and if it doesn't match what it's coded to in the VBA then it logs the users information and kicks them out of the database.

My question is can I use VBA to check if the current user -Environ("USERNAME")- matches one of a few cells in a table and then execute my code based off of the result.

Table name is "AccessListing" and the row "IDNUM" contains the few members USERNAME.

My reasoning is because I will not always be working in my position, so I'm trying to make it fool proof. This way when I leave, the next person won't jack it up.

user2002716
  • 120
  • 2
  • 11
  • 1
    When following the duplicate link to the answer, especially pay attention to the first comment to that question and to the accepted answer: There is no such thing as security with Access databases. And you should never trust an environment variable. – Leviathan May 06 '16 at 21:52
  • A better way than `Environ("USERNAME")` is `CreateObject("WScript.Network").UserName`, see http://stackoverflow.com/q/34352511/3820271 – Andre May 07 '16 at 07:34

1 Answers1

1
if Dcount("IDNUM","AccessListing","IDNUM = '" & Environ("USERNAME") & "'") > 0 then 
'do something when user is in list
else
'do something when user not in list
endif

Be aware that Environ("USERNAME") is not secure, it could be manipulated!

user424242
  • 61
  • 2
  • This worked! The database is on a shared network and everyone is required to login to the computers with ID cards and no admin rights, so nothing to worry about for them bypassing it. The user name reads as their name and they can’t change it on the system at all. – user2002716 Mar 29 '18 at 03:49