Results 1 to 7 of 7
  1. #1
    Stoic is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    4

    Display username on a form from a user table

    Hi,
    I have a database that has a table called tblUsers containing username and password. I also have a userlogin form for users to enter their username and password if they have permission to the database. Now, I would like to display the username on the welcome form based on the user that has entered the database, not the system user name.
    Any help will be appreciated.


    Thanks

  2. #2
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Not a problem. This can be done with a label.

    Create a label on your form where you want the username to display...

    This is what I use, it is kind of specific to how your table is built. My table has 3 columns

    First column contains a list of Programs, things we are storing credentials for... Second column is a list of their usernames, and the third column holds a list of passwords... If you could post a snapshot of your table, I could modify the code below to work for ya.

    Code:
      Dim User as String
    
    
      User = DLookup("[chrWebuser]", "tblWebCreds", "chrWebTools='ProgramName'")
      me.lblUsername.caption = User

    So User = something under the chrWebuser column, where the chrWebtools = program name. And it is looking at the tblWebCreds to gather all this information..

    Then we set the label to = user... bada bing

    So yea, please post a pic to your table (without usernames) and tell me what the label name your going to use is and I can finish this up for ya.

  3. #3
    Stoic is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    4
    Thanks for responding. I have attached a picture of my user table for further assistance.
    Click image for larger version. 

Name:	UserTable.png 
Views:	10 
Size:	168.3 KB 
ID:	11233

    Also am I placing the code in the afterupdate on the user login form userpassword and username fields? The label name is txtCurrentUser.
    Please help.
    Thanks again.

    Quote Originally Posted by redbull View Post
    Not a problem. This can be done with a label.

    Create a label on your form where you want the username to display...

    This is what I use, it is kind of specific to how your table is built. My table has 3 columns

    First column contains a list of Programs, things we are storing credentials for... Second column is a list of their usernames, and the third column holds a list of passwords... If you could post a snapshot of your table, I could modify the code below to work for ya.

    Code:
      Dim User as String
    
    
      User = DLookup("[chrWebuser]", "tblWebCreds", "chrWebTools='ProgramName'")
      me.lblUsername.caption = User

    So User = something under the chrWebuser column, where the chrWebtools = program name. And it is looking at the tblWebCreds to gather all this information..

    Then we set the label to = user... bada bing

    So yea, please post a pic to your table (without usernames) and tell me what the label name your going to use is and I can finish this up for ya.

  4. #4
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Alright, I would suggest adding a column BEFORE strUserID, some way of identifying what that username is for. Because not only can the label display it, but it will be easier to reference at any point during the code..

    this would become something like this...


    Okay, you see how I spaced this "chrWebTools='ProgramName'") way out?

    I did that because you need to add an extra column.. If you add an extra column and named it strProgram then next to the DBAadmin and the other username use an indicator as to what that username is for... then it can be referenced using my method. I'm sure its not required but trust me it will make life easier.


    Dim User as String User = DLookup("[strUserID]", "tablenamehere", "chrWebTools='ProgramName'") me.txtCurrentUser.caption = User

  5. #5
    Stoic is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    4
    Thanks but I am getting an error message:
    Click image for larger version. 

Name:	Error.jpg 
Views:	10 
Size:	86.6 KB 
ID:	11237

    Click image for larger version. 

Name:	tblUsers.jpg 
Views:	7 
Size:	34.3 KB 
ID:	11238


    Also I do not know if I am placing the code in the right place. Am I creating a label with this name chrWebTools?
    I am not catching it yet.
    Please help.

    Quote Originally Posted by redbull View Post
    Alright, I would suggest adding a column BEFORE strUserID, some way of identifying what that username is for. Because not only can the label display it, but it will be easier to reference,at any point during the code..

    this would become something like this...


    Okay, you see how I spaced this "chrWebTools='ProgramName'") way out?

    I did that because you need to add an extra column.. If you add an extra column and named it strProgram then next to the DBAadmin and the other username use an indicator as to what that username is for... then it can be referenced using my method. I'm sure its not required but trust me it will make life easier.


    Dim User as String User = DLookup("[strUserID]", "tablenamehere", "chrWebTools='ProgramName'") me.txtCurrentUser.caption = User

  6. #6
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    post a copy of your database. I'll fix it up. Instead of using a label, you used a textbox.. textboxes do not support .caption, but have to use .value instead.

  7. #7
    Stoic is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    4
    My database is a large file and I am not able to upload it with my internet connection.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 08-17-2015, 02:32 AM
  2. Replies: 5
    Last Post: 08-08-2012, 01:28 PM
  3. Replies: 11
    Last Post: 07-24-2012, 07:50 PM
  4. Username/Password From Table
    By mj-egerton in forum Programming
    Replies: 0
    Last Post: 04-03-2011, 04:46 AM
  5. Replies: 3
    Last Post: 09-29-2010, 08:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums