473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Autopopulate a field based on logged in person.

111 100+
I have custom login interface. When the user logs in I want to show something like "Welcome John Doe" on my switchboard form? How to do it? Hint please!!
Also, when the user selects "Open data entry form", the field called ModUserID should be populated with the person who is logged in right now.
Open Data Entry form : frmOpendataentry is bound form. the table it is bound to is tblRadioDataEntry.

Thanks

PS: I tried to define "Default value" property on both table and/or form. It does not work. When I open the form it sayes "#Name" in ModUserID field.
Dec 1 '09 #1
11 8272
ChipR
1,287 Expert 1GB
You can use the code here [http://www.mvps.org/access/api/api0008.htm] to get the login name of the user. You will likely want to have a table of login names, actual names, and other info for users.
Dec 1 '09 #2
topher23
234 Expert 100+
You need to create a table that has each user's real name, username, etc. The user will log into the database using their username, then you will use the username to pull the real name from your users table.

If you are using Access 2003 or earlier with User-Level Security set up, you can get their username via the CurrentUser() function. If you are not using User-Level Security (which is really the better option) and you don't have any other secure login mechanism set up (which you really need), you can get the username from Windows using the ENVIRON() function. Check this thread for more on security and the ENVIRON() function http://bytes.com/topic/access/answer...assword-access.
Dec 1 '09 #3
topher23
234 Expert 100+
There may also be a problem here with terminology.

By "custom login interface" do you mean an actual login form where the user enters a username and password, or do you mean a customized switchboard?

You say that when the user opens a form, a field called ModUserID should be populated with their name. Do you mean a control on the form or an actual table field?

And finally, what are you trying to set the default value of your control to?

Okay, I think I'm done with questions for now. This is what I'd do if I were you.

In the database is the following table:

Expand|Select|Wrap|Line Numbers
  1. tblUsers
  2.  
  3. Field           Type
  4. UserID          AutoNum  PK
  5. strLastName     Text
  6. strFirstName    Text
  7. strMI           Text
  8. strUserName     Text    (no duplicates)
  9. strPassword     Text    (encrypted)
  10. strPermissions  Text    (access permissions)    
  11.  
In a module, declare a public variable
Expand|Select|Wrap|Line Numbers
  1. Public plngCurrentUserID as Long
When the user logs in to the custom login form using the username and password from tblUsers, set plngCurrentUserID to the UserID corresponding to strUserName. Now, whenever you need something regarding that user, such as their permissions or name, you reference plngCurrentUserID. For the field you want to populate, you'd use a couple of DLookup functions, like so, in the ControlSource property.

Expand|Select|Wrap|Line Numbers
  1. ="Welcome, " & 
  2. DLookup("strFirstName","tblUsers","UserID = " & plngCurrentUserID)
  3. & " " & DLookup("strLastName","tblUsers","UserID = " & plngCurrentUserID)
  4. & "!"
This is the method I use. If anyone else knows of a better way, please share!

P.S. For encrypting the password using an MD5 hash, I use Robert Hubley's MD5 class module. I believe the version I am using is available here http://www.freevbcode.com/ShowCode.Asp?ID=741
Dec 2 '09 #4
AccessBeetle
111 100+
Thank you guys for the reply!! The mistake I was doing was, I was closing the login form using
Expand|Select|Wrap|Line Numbers
  1.  DoCmd.Close acForm, "frmLogin", acSaveNo
.That is why the value in the txtUserName was not avaialble for rest of the forms. What I did was I replaced that line with this one
Expand|Select|Wrap|Line Numbers
  1. Me.Visible = False
  2.  
.
So now, it does catches the value of txtUserName for rest of the open forms.
ANyways, I never thhought this far(like you guys have answered!!) It is nice thought to get an insight.!!
Thanks again!!
Dec 2 '09 #5
AccessBeetle
111 100+
Topher,
I guess I solved my questions. I have all the fields you have mentioned in the table except for "strPermissions". Please let me know how I can use this field to set the user level permissions? For ex. Only Supervisor will have access to add more users and not the regular users.
P.S
By cutom login interface, I mean no switchboard. I created a form called frmLogin which has data entry fields called UserName and Password and commands like Forgot password, Can't sign in. etc
(the rest of the questions are taken care of, thanks to you guys)
Dec 2 '09 #6
topher23
234 Expert 100+
Beetle,

strPermissions was oulined in the thread about passwords and security that I referenced in post #3. The field contains several two-letter abbreviations for different permissions. When a form loads, it checks to see if the user has permission to use different controls by using the InStr() function to see if the controls' two-letter permissions are in the permissions string.
Dec 2 '09 #7
AccessBeetle
111 100+
Can you give me some example? Where to start, I suppose?? I mean I am getting something like this in my mind.
Expand|Select|Wrap|Line Numbers
  1.          UserId    strFirstName   strLastName       strPermission
  2.             1           John             Doe                Supervisor
  3.             2           Jill                Smith             Manager
  4.             3           Mike             McDonald       User
Can we control access to each and every form via this?
For example, The users who have "Supervisor" permissions, only they can edit data of users under them?
Thanks for help.
Dec 2 '09 #8
topher23
234 Expert 100+
The problem with using titles like "Supervisor", "User", "Admin", etc. for permissions is that you run into issues such as a Manager needing access to a resource that normally belongs only to Supervisors. You want to give that Manager access to that area, but you don't want to grant him Supervisor access, nor do you want all Managers to have access to that area. Uh oh, dilemma time. That's where the permissions the way I was talking about come into play.

If you set a different permission code for each asset you want protected, you can assign the code to any user who needs it.

In order to secure a resource and allow users access to it, you would need to set up something in code, like so.

Assume a main switchboard called frmSwitchboard. On the switchboard you have a button called cmdOpenAdmin that opens the Database Administration menu form. Obviously, you don't want everyone getting into that form, since they could wreak some major havoc in there. So, in the OnOpen event of your form, you place code that checks the user's permissions and then sets cmdOpenAdmin.Visible to True or False based on whether they have permission to view it or not. The same would also be done for any control on the form that you don't want all users to have access to.

Does that outline make enough sense that you can run with it?
Dec 2 '09 #9
AccessBeetle
111 100+
Your explanation does makes sense and I think I will be able to figure out something based on that. Thanks for taking time to explain.
Really, i was not even thinking of having some field like 'strPermission'. But I think this way it will be easier to define groups.
Thanks again!!
Dec 2 '09 #10
hi topher23

I have a question for you....i have an access database with several table, one of those being a user table with Username, First and last Name fields. I would like to create a field on another form and have it auto populate the full name of the user based on their login in. Would also like to "lock" this field and prevent the current user or any other user from editing it...thanks
Jan 31 '19 #11
twinnyfo
3,653 Expert Mod 2GB
cariboybgi,

Welcome to Bytes!

You may want to take a look at this thread on User Permissions and Customized Menus. Once you understnad that Access recognizes the particular user, you can use whatever you want in the user table at will. You can also expand the User table to include whatever data you desire (such as First and Last Names).

Hope this hepps!
Feb 1 '19 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: BK | last post by:
Hi, I have a problem. I need to auto populate fields based on a value entered in combo box. Initially, I put all the required fields in the combo box, and hide it (set to 0",0",0", ...), then...
14
by: SpyderSL | last post by:
Hey, I have created an access form, in which I have a drop down with employee names. These are the steps I would like to happen: 1. A user will enter a number in FIELD A 2. The user will...
1
by: compl | last post by:
I have a database that I need to restrict the ability to edit one field based on another. The two fields are DOS (date) and Amount (currency). I only want the users to be able to edit the Amount...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
2
by: mvlt | last post by:
I would like to set-up an email data collection to gather volunteer hours from our volunteers. Is there a way to auto-populate a field if I use the HTML format. Each volunteer has a Contact ID, but...
5
by: Shortstuff12345 | last post by:
I'm trying to use VBA code to disable a field based on the value of another field in a form. The code I have properly updates the enabled property of the field when it changes; however, it changes...
3
by: hkim8392126 | last post by:
I've been searching and reading the forum, but with no success to find what I was looking for. I am trying to autopopulate a field in a form. I am not sure if I need to create a query or table to do...
20
by: Bigdaddrock | last post by:
Using attached database. Open Form "DH ADD ORDERS w/Tax". I would like to autopopulate the bound control "INVNUM". It's source would be the field INVNUM in the table INVOICE. I was hoping to...
1
by: Kanapaha | last post by:
The table is tblOfficeLocations, which has 3 fields; Office_Code, Office_Name and State_Country. When I select the in cboLocation, I want the field to autopopulate with the State_Location. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.