Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2006
    Posts
    20

    Unanswered: Extract portion of user login

    Is there any way you can extract a portion of the user login (or username) and save it into a table field every time the user logs into the database?

    For example, if the user's login name is 'John.Smith', it would just display 'Smith' in the textbox.

    I understand the currentuser() function can be used for this but I'm just not sure how to extract data from it. Any help would be greatly appreciated. Thank you so much!

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You can use the Mid() function along with the InStr() function to find the position of the period.
    Paul

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Code:
        Dim c_user As Variant
        
        c_user = Split(CurrentUser(), ".")
        c_user = c_user(1)
    Have a nice day!

  4. #4
    Join Date
    Nov 2006
    Posts
    20
    Thank you so much, pbaldy and sinndho. I will sure to try that tonight. I just have to figure out how to use the InStr function. Thanks again!

  5. #5
    Join Date
    Nov 2006
    Posts
    20

    Extract portion of user login pt 2

    Thank you again for your help pbaldy and sinndho. I used the methods you provided and they worked great! However, I do have one other question:

    Why is it that when I tried the following sql statement, it would not let me push the data into a field in my table?

    dim c_user as variant

    c_user = split(currentuser(),".")
    c_user = c_user(1)

    DoCmd.SetWarnings False
    DoCmd****nSQL "INSERT INTO myTable (field1)" & _
    "VALUES ([c_user]) "
    DoCmd.SetWarnings True

    What I'm trying to do with this is to record the username without the users knowing (sort of recording their login).

    I'm trying to figure out what I'm doing wrong. Thanks again!

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Try

    " VALUES ('" & c_user & "') "
    Paul

  7. #7
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    Just a quick question how will you distinguish between two people with the same surname?

  8. #8
    Join Date
    Nov 2006
    Posts
    20
    Thank you so much again pbaldy. I'm trying to follow the help provided by Microsoft but most of the time they just don't work. I can't believe I didn't even think about putting the quotes...thank you!



    -- hello poppa smurf...I don't think it's going to matter if they have the same surname as long as it identifies the user as far as what I'm trying to do...thanks for the question
    Last edited by aiikahn; 07-30-09 at 09:49.

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so you ave two users john.smith and jane.smith
    you are truncating the surname, so how will you tell which smith is which?

    given that you can have multiple people logged on to an Access application called john.smith.. there is no way you can ever guarantee the value in currentuser is actually the persont hey say it is... userid's and passwords are nowhere near as secure as the network logon. if you want some eye candy then currentuser() is fine, if you want the data to have any meaning then use the network logon
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Nov 2006
    Posts
    20

    Extract portion of user login p3

    Thank you Healdem. You are certainly right about it. I guess I'll have to do both first and last.

    But I have another issue. I finally got SQL working (thanks pbaldy) but it puts data in a separate record. When the submit button is clicked on the form, it puts the form data in one record and then the 'username' in another.

    I tried using the following methods: onclick, afterupdate, current, beforeupdate - but it still separating the data.

    Is there anything that I'm missing here...thanks again for your help!

  11. #11
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Well, that's what your SQL statement does; creates a record with that one value. If your form is based on the same table, you should just set a bound textbox to your value.
    Paul

  12. #12
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by aiikahn
    Thank you Healdem. You are certainly right about it. I guess I'll have to do both first and last.
    I don't think you get the point at all
    many people can logon onto an an access ap using the same userid and password combination, assuming they know both items, there is no inherent mechanism within an Access logon which validates a person is actually who they say they are.. don't believe me

    open up your app on two spearate workstations logon with the same userid...

    although network logons can be duplicated (depending on your user profile and so on) its easier to block if the network trolls only allow one account per person and one logon session active at any one time. by using your current approach you have the potential to have more than one john.smith usiing the same access application at the same time. to me becuase current user cannot be trusted to deliver ONLY the true current user the oinforamtion it provides is worthless.. it canot be relied upon. if you also store the computer ID then you may have a caase.. but if you are going down the route to get the computer name you might aswell use the netwrok logon at the same time.

    when used in a security context...
    using the network logon means that you can effectively dispense with the need to logon when using access as the user is already authenticated by network logon, the ability to open the app is given by the user profile and permissions at network level. "all" you need to do at application level is verify what usergroup that network logon is assigned to and whether they have permissions to use that object
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •