Database User Name Displayed on Welcome Form (1 Viewer)

pr2-eugin

Super Moderator
Local time
Today, 00:36
Joined
Nov 30, 2011
Messages
8,494
Hi Paul, I am trusting that all is well;
Things are okay.. Work's been stressing.. But alright, thanks.. Hope they are well with you too.. :)
I have been doing well with my database but something else came up that I thought to seek your advice on.
1. Instead of the username appearing on the form after login success, I would like to use the actual name of the person that have entered the database. That means in my tblUser table, I already have username, password, user actual name, position, ect. Is it than possible to replace the lookup colom [username] with the actual name colom?
Yes, you have to change the code from a simple
Code:
pubStrUserID = Me.txtLoginID
into,
Code:
pubStrUserID = DLookUp("[COLOR=Blue][B]actualUserName[/B][/COLOR]", "tblUsers", "strUserID = '" & Me.txtLoginID & "'")
Although you can merge it with the Recordset, thus making your code more efficient, by avoiding the use of DLookUp..
2. I would also like to include in my tables if user X is entering data, a colom should show the username of user X against that data with entry date in another colom.
There are many ways to do this.. Creating a Logger table, Or just two other columns in the table, with user name and Date modified and then use the BeforeUpdate event of the Form, where you check if it the New Record (taking the assumption), and fill those information..
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.NewRecord Then
        Me.[COLOR=Blue][B]theNewUserFieldName[/B][/COLOR] = pubStrUserID
        Me.[COLOR=Blue][B]theNewDateFieldName[/B][/COLOR] = Date()
    End If
End Sub
Hope this helps..
 

Stoic

Registered User.
Local time
Today, 00:36
Joined
May 15, 2013
Messages
24
Good to hear that all is well. Thanks for the support, I will let you know if it does, but I am quite sure that it will.
Regards,
Oscar
 

Users who are viewing this thread

Top Bottom