Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481

    User Login Details!

    Hi

    I am using the below codes to record the user details who entered or update the data;



    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    
        UpdatedBy = Environ("username")
        UpdatedOn = Now()
    End Sub
    
    
    Private Sub Form_Current()
    If Me.NewRecord Then
            EnteredBy = Environ("username")
            EnteredOn = Now()
    End If
    End Sub
    and its working fantastic but getting the system user as used "Environ" but DB the has its own login details as UserName, Password, etc "TblSecurity" which can use the given user credentials or system user "Default Value: =fOSUserName()" after assigning the password to the system user in "TblSecurity".

    Requirement: How to get the either user details at form current and before update events.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    tblSecurity needs field for the system user name. Then grab username from system and use DLookup() to pull the corresponding db user name.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    *The System user is updated in the "TblSecurity" by assigning a password like others, otherwise he cant logged in the DB.

    The issue is only to record the Last Entered and Update fields by the logged user (either system or other user) but right now those fields picked up the System user in each table.

    SO a help with code for DLookup () should be appreciated.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    If users have to use db username and password to login, why are you grabbing system username?

    I have code that gets Environ("username") and looks for record in tblUsers. If not found then this is first time user and a 'login' form pops up for them to enter initials. Code creates record in tblUsers. User never sees the login form again. There is no password.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Well, Yeah you are right and i should not mix up with system user.

    There is no issues with the login entry form as it is controlled by the TblSecurity.

    The issue is only to get the real user name of "TbleSecurity" who entered or updated the records.

    As given above code, used at form which picked up only system user rather than logged user.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    You don't really need the system username?

    User logged into workstation might not be same individual who logs into the db on that workstation?

    When user logs into db save the db username somewhere so it can be referenced at anytime, from anywhere in the db. I save user info on a form that never closes (MainMenu). Other options are global variable or TempVars.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Yeah, i dont think so but u have a advance option which is better but in my case we dont need it. Lets Setup users at start or later in TblSecurity to get permission to logged in at any work place.

    No one should logged in the system until have proper assigned user name or password.

    So kindly advise for the requirements.

  8. #8
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I'm a bit confused. Hopefully the following is correct

    You want to store the logged in user name rather than Environ("UserName") as these may be different.
    So when the user logs in, just store that info as a variable e.g. strCurrentUser
    Then have a public function GetCurrentUser and set that equal to strCurrentUser

    You can then use GetCurrentUser throughout your application as needed
    Or you can use a tempvars if preferred.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Well, Yeah its true.

    So shall be the code like that?
    Private Sub Form_BeforeUpdate(Cancel As Integer)


    UpdatedBy = strCurrentUser
    UpdatedOn = Now()
    End Sub


    Private Sub Form_Current()
    If Me.NewRecord Then
    EnteredBy = Environ("username")

    EnteredOn = Now()
    End If
    End Sub

  10. #10
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Sorry means like that?

    Private Sub Form_BeforeUpdate(Cancel As Integer)


    UpdatedBy = strCurrentUser
    UpdatedOn = Now()
    End Sub


    Private Sub Form_Current()
    If Me.NewRecord Then
    EnteredBy = strCurrentUser
    EnteredOn = Now()
    End If
    End Sub

  11. #11
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    The last two posts look the same to me.
    That's not quite what I said which was to refer to a function.
    What do you think will happen using both of these ?
    Have you tried it?
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  12. #12
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Well, yeah with little correction.

    For sure, its not working at all.

    I am not a expert even not have the functions idea, so kindly explain what you said?

  13. #13
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    OK. Here's one method. Change all control names as appropriate

    1. Create a Public variable in a standard module
    Code:
    Public strCurrentUser as String
    2. on the login form,
    Code:
    Private Sub cmdLogin_Click()
    strCurrentUser=Me.txtUserName
    
    End Sub
    3. Add this code to a standard module
    Code:
    Function GetCurrentUser()
        GetCurrentUser=strCurrentUser
    End Function
    Now you can get the current user at any time by just calling the function

    Code:
    EnteredBy = GetCurrentUser
    Hopefully you can do the rest yourself
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  14. #14
    cap.zadi is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Location
    KSA
    Posts
    481
    Hi, Thanks for the idea and help but i am not expert like you even at very starting level.

    Anyways, i will try. Thanks

  15. #15
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    You could have a look at this example database on my website http://www.mendipdatasystems.co.uk/p...gin/4594469149

    Good luck. Come back if you get stuck
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 10-23-2016, 07:35 AM
  2. Replies: 3
    Last Post: 12-14-2011, 01:24 PM
  3. Replies: 6
    Last Post: 12-12-2011, 01:28 PM
  4. Replies: 1
    Last Post: 12-11-2011, 11:48 AM
  5. Replies: 3
    Last Post: 09-22-2011, 03:35 PM

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