Modules & VBA :: Use The Environ Username Somewhere In The Db?
Mar 27, 2014
Using Win 7 and Access 2007
db will be split and on a server
If it's possible: Would like to use the Environ username somewhere in the db so the user only sees their records.
Where would I place this? Or is their different code I should be using for this purpose???
I am trying to use the Environ Username function, which i have working! But i want to compare the result with a Username Table to determine if they have access etc...
How do I use the following as the default value of a textbox in Access2003? Environ$("USERNAME")
Resolution:
Create Module and insert the following code:
Option Compare Database Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String On Error GoTo fOSUserName_Err
Dim lngLen As Long, lngX As Long Dim strUserName As String
Hi I am using the below code for getting Windows Username, this code is working fine when i am using this in lable, however if i use this in a query, it is not working, do it need some kind of autorun?
SELECT Associates.* FROM Associates WHERE (((Associates.CorpID)=Environ("UserName")));
I have noted a problem on 2 computers using this. There are around 30 or so computers on our network that work fine with this as a value. The majority of the users are at Access 2000 but some have Access XP. The offending machines have Access 2000
One day a persons computer crashed. DP imaged another persons machine and installed the image on the crashed machine as a solution. Since this the =Environ("username") returned #Name$ (not sure of the exact syntax on this). This same trouble surfaced on another machine recently. I unlocked the field so the users could enter their correct name but this can lead to errors and I would like to keep the username locked and read by code.
I checked the references on the offending machine and they were ok. Not sure what else there is to do to rectify this.
If anyone else has had a similar trouble and found the solution I would appreciate hearing about it.
Thanks a lot!! ----------------------------- Edit: I just checked the machine and corrected the syntax above. I also found that in a date search form where I have =now$() for a field, the same thing is displayed - #Name$ rather than the date.
I'm trying to find a code that will allow me to check a value of a yes/no checkbox based on a username.
What I want to happpen is:
1. The code looks to see if the username that is entered in "txtUsername" field on the form matches the "empUsername" value on the table "tblUsers." 2. If there is a match, I want it to look at the value for the field "Admin" on "tblUsers" to see if the value is checked as true. 3. If the value is true, I want it to open a specific form "frmAdmin." If it is false, I want it to open a form "frmMain."
VBA codes not recognizing the Admin field and instead taking all users into the frmMain.
I'm working on creating an events log. In my table I've got a field that pulls the individual's username (that they use to log into the computer) and logs it against their log entry.
As part of my query (for my daily events log report) I'm pulling up said username.
I'd like to give access to the specific user to edit his (and only his) entries from the report, but I'm getting a type mismatch with the below code:
Code: If me.UsernameID = "KraussLJ" Or Environ$("Username") Then DoCmd.OpenForm "frmShiftLog" DoCmd.FindRecord Me.ID, acStart, , acSearchAll, , acAll Else MsgBox ("You are not authorized to edit this entry") End If
(before you ask, "KraussLJ" is our ops manager who insists on having final editorial control over the shift log before sending it higher up the chain)
I can get the msgbox to run if I block out the
Code : Environ$("Username")
, but beyond that I'm a little stuck. Should this be a dlookup function or am I overanalyzing this way too much?
I use Environ("Username") all the time, most frequently for logging who has done something to a record, and have once used it to log people into the database (very basic, much the same as logging who did what to records).
But I was wondering, how feasible is it as a security measure?
I often use it on the main menu of my DBs to give me a different menu (with more advanced options on) than other users.
Is it really that safe to use it as a means to allow people in, or stopping them? I know that obviously you have to stop them getting in other ways (holding shift for example), but assuming all of that is done, in theory, they should only be able to get in if they can log in as an authorised user?
Don't know why it is just struck me - just curious I suppose!
I have searched for help on this forum and all over for a while but cannot find the help i need.
I have a database stored in my user area on a schools network. Other users around the school access the database by clicking on a shortcut to it found on their start menu. The database is not split with a fe/be and usernames and passwords are not required to log on, they simply click the link.
I would like to know how I can find out which users have the database open at any given time? I have a piece of software that tells me the computer name but that is no use, I need the users name. Is there a way of pulling this from the network because each user must first log on to their computer using their name and password before they can access the database?
i have a menu which recognises a user by using the environ function.
the problem i am getting is that with a small number of users the environ function isnt recognised by the system?
it gives them a #name# instead.
the crazy thing is that it also happens on simpler functions such as =Now() and =Date() which is really annoying, as these 3 things are a foundation on anything that is done within the system/!
the majority of users have no problems, which makes it even more annoying!
when i try to go into the properties of the label which has been assigned the function i get a message. (only on affected PC's)
I have the security set via the Access workgroups for both groups and users. I want to be able to use the username entered on the logon screen to filter my query results.
How can I get the logon id that was entered when my switchboard form opens?
I have entered the following code to an onclick button. I am sure I have written it incorrectly (it's probably the line I highlighted below to do with username=Manager. By the way Manager is one of my usernames I have created.
Thanks for your help.
Rob
Private Sub Label218_Click() If UserName = Manager Then DoCmd.OpenReport "Tennis Teams", acNormal Exit Sub End If MsgBox "You do not have permission to open this form!", vbOK, "Tennis Center Business Manager 2007" End Sub
I need the dB to automatically pick up the username of the user logged on to the PC. Thus if I'm logged on to the PC as FLESTER, this username wil populate a database field.
How do you get Access to pick up th OS username currently logged in to the database? For example I'm logged on to the PC as FLESTER and I wnat that recorded in the dB.
A couple of questions. I want my database to query the AD and make sure that the user trying to open the database had an account in the AD. I dont want them prompted for a password though. I have had a look at trying to change the example NT logon in the samples area, but just managed to get myself in a bit of a mess. Also is there anyway that you can query the users full name in AD and call that variable,or does this only work with the username?
Also, when a user created a record in a from, I would like the users username, called from the AD saved in a field in the table. I have tried this and the only way that I can call the variable is by having the "=Environ("USERNAME")" in the control source of the text box. Which means that it cant be save in a field in the table. I have also tried an after updated event on that textbox to update another textbox and have that textbox control source a field on the table. But again this doesn't work. Can someone tell me if what I am trying to do is possible. Thanks
I am currently trying to create a form that will have the ability to show the last person that edited that form and the time and date that it was last modified. When I try though I just keep getting the field to update to me just by viewing it. Can anyone give me a fairly detailed way of doing this?
I created a password for my database and now I cannot access it. The dialog box says that either the username or password may be incorrect. I do not know what the requested username is. I do not recall creating a username during the process of creating the password. I do not know what username ACCESS is asking for. I think I know what the password is. I think the problem is the username. However, if I somehow do not know the password, what can I do?
After you finish laughing at me, please help. Thanks for any assistance you can provide.
I want to secure my Access database with a username and password. I want to be able to pull the nt login of the user and have them access only the things i need them to access. How can I do this?
Hello! I have a problem regarding using usernames and passwords to restrict access to certain tables/forms/reports etc.... I have read around the forum and various other websites but cant seem to get much relating to exactly what i am wanting to do.
I think i understand the way the access workgroup security works. But does this not just restrict users being able to view the database as read-only or with other certain rights like that? So, firstly would i be able to use this to restrict the database the way i want?
Or is there a way to create a table with names and passwords and create a form at the beginning where the user inputs their details and then according to the details gives/restricts access to parts of the database? Ideally i'd like the startup form to direct them to a different menu according to the user which gives them only the options they are allowed?
Seems a bit of a mouthfull and i sound like a complete newb but i been trying to figure this out all day!! Thanks