|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Display logged on user - Stupid question #1Apologies if this is a bit of a basic question for on here, but I want to display the current logged on user on a form. I don't want to show the actual logon name, I want to show the real username. e.g. logon name: bloggsj display name: Joe Bloggs I *think* I know how to do this with DLookup, but is this the best way of doing it? i.e. =DLookUp("EmployeeName","TBL_Employees","EmployeeLogon"=CurrentUser()) I heard DLookUps are bad... TIA, Andy
Show quote
Hide quote
"Pecanfan" <pecanfan@no.spam> wrote in message They can be slow with high data volumes. An alternative would be a select news:1130251688.858248@smtp-1.griffin.com... > Hi, > > Apologies if this is a bit of a basic question for on here, but I want to > display the current logged on user on a form. I don't want to show the > actual logon name, I want to show the real username. > > e.g. > logon name: bloggsj > display name: Joe Bloggs > > I *think* I know how to do this with DLookup, but is this the best way of > doing it? > i.e. > =DLookUp("EmployeeName","TBL_Employees","EmployeeLogon"=CurrentUser()) > > I heard DLookUps are bad... > SQL statement in the form's open event (untested): dim db as DAO.Database, rs as DAO.Recordset, strSQL as string strSQL = "Select EmployeeName from TBL_Employees where EmployeeLogon = " & CurrentUser set db = Currentdb set rs = db.OpenRecordset(strSQL) rs.MoveFirst Me.txtMyTextBox = rs!EmployeeName rs.Close db.Close set rs=Nothing set db=Nothing You'd have to code for things like there being no entry in the table for CurrentUser ... maybe other instances too but can't think just off the top of my head ... anyone? HTH - Keith. www.keithwilby.com Pecanfan wrote:
> =DLookUp("EmployeeName","TBL_Employees","EmployeeLogon"=CurrentUser()) Nope, the third parameter is not correct. Try this (spaces added forclarity): = DLookUp ( "EmployeeName", "TBL_Employees", "EmployeeLogon=""" & CurrentUser() & """" ) > I heard DLookUps are bad... DLookup is fine for your purpose here.HTH, TC > > =DLookUp("EmployeeName","TBL_Employees","EmployeeLogon"=CurrentUser()) Cheers for the replies - noticed my typo after pressing 'send' - d'oh! The> > Nope, the third parameter is not correct. Try this (spaces added for > clarity): > > = DLookUp ( "EmployeeName", "TBL_Employees", "EmployeeLogon=""" & > CurrentUser() & """" ) > > > > I heard DLookUps are bad... > > DLookup is fine for your purpose here. following also seems to work:- =DLookUp("EmployeeName","TBL_Employees","EmployeeLogon=CurrentUser()") Any reason for the extra quotes in your version? Cheers, Andy > Any reason for the extra quotes in your version? The third parameter to DLookup() is a string expression which, whenevaluated, is the WHERE clause for the DLookup. That is, the third parameter should evaluate to a string, that string being a boolean expression which in turn evaluates to true or false. Say CurrentUser is "Fred Smith". 1. "EmployeeLogon"=CurrentUser()) is actually a /boolean/ expression which evaluates directly to True or False, depending on whether the current user's name is or is not "EmployeeLogon", respectively. That is clearly not what you want! The parameter should be a /string/ expression, not a boolean one. 2. "EmployeeLogon=""" & CurrentUser() & """" is a /string/ expression which evaluates to the following boolean expression: EmployeeLogon="Fred Smith" 3. "EmployeeLogon=CurrentUser()" is also a string expression, which evalues to the following different, but functionally equivalent, boolean expression: EmployeeLogon=CurrentUser() HTH, TC
Security change takes effect only locally, not on server
TC - New security model Relink tables in a secured DB - create table permission required? Database Access problems MDE security issue Guru's please help ... Removing Security settings Access security model Securing the Back-End How to control the number of installed front end files (*. mde) Export or Import Objects from One Secured Database to Another |
|||||||||||||||||||||||