ِAdd Name of the data updater in table . (1 Viewer)

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
Hello all . I have a database that has access to a group of users based on the username through a Combo Box list and the password field. In the main table, I have two fields, the date of the update and the name of the data updater. The form has a save button. When the user clicks the save data button, the event automatically adds a date in the update date field in the table. What I also want is to automatically add the database user name in the data updater name field based on the fact that he is the one who opened the database with his password and name as well.Thanks to all
 

June7

AWF VIP
Local time
Yesterday, 17:27
Joined
Mar 9, 2014
Messages
5,466
At time of login save user name somewhere it can be referenced when needed. Options: populate an unbound textbox on a form that never closes (MainMenu), global variable, or TempVar.

I have a 'login' process that doesn't require user to enter name and password. I use their Windows network login because if they can login to network they are valid uses.
 
Last edited:

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
At time of login save user name somewhere it can be referenced when needed. Options: populate an unbound textbox on a form that never closes (MainMenu), global variable, or TempVar.
Thanks for the quick reply. The username and password are in a separate table and I hid it and made it one of the system tables. There is a way that the user name appears in the footer of the report based on a function. But I could not add it to a field in the form.
Code:
Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
 (ByVal lpBuffer As String, nSize As Long) As Long
 
' Main routine to retrieve user name.
Function GetLogonName() As String
 
 ' Dimension variables
 Dim lpBuff As String * 255
 Dim ret As Long
 
 ' Get the user name minus any trailing spaces found in the name.
 ret = GetUserName(lpBuff, 255)
 
 If ret > 0 Then
 GetLogonName = left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
 Else
 GetLogonName = vbNullString
 End If
End Function
 

June7

AWF VIP
Local time
Yesterday, 17:27
Joined
Mar 9, 2014
Messages
5,466
Why can't you add to field on form? Use VBA behind form to call function and populate field.
 

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
Why can't you add to field on form? Use VBA behind form to call function and populate field.
Because this function adds the name of the computer and not the name of the user through the interface that I made.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:27
Joined
Feb 19, 2002
Messages
43,233
In the BeforeUpdate event of the form, use:
Code:
Me.UpdateBy = Environ("UserName")

Or use the saved login name.
 

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
In the BeforeUpdate event of the form, use:
Code:
Me.UpdateBy = Environ("UserName")

Or use the saved login name.
It didn't work and I also put the function I referred to in the report and I also get this error message
 

Attachments

  • 33.JPG
    33.JPG
    34.7 KB · Views: 341

Gasman

Enthusiastic Amateur
Local time
Today, 02:27
Joined
Sep 21, 2011
Messages
14,238
1. You do not need the Value property
2. You have a space before .Value, so Access does not see it as a property of txtUser 😔
 

June7

AWF VIP
Local time
Yesterday, 17:27
Joined
Mar 9, 2014
Messages
5,466
Because this function adds the name of the computer and not the name of the user through the interface that I made.
I am confused. Your function states "get the user name" not "get the computer name".
 

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
1. You do not need the Value property
2. You have a space before .Value, so Access does not see it as a property of txtUser 😔
Yes, correct . Fixed but leaves field blank without username.The name appears to me on Textbox, but it does not appear in the table field or is added
 

Attachments

  • 33.JPG
    33.JPG
    22.1 KB · Views: 359

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
I am confused. Your function states "get the user name" not "get the computer name".
Is there another example based on the functionality or permissions of the users, admin, user, developer, etc. that the admin can see who updated the information?
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:27
Joined
Sep 21, 2011
Messages
14,238
Yes, correct . Fixed but leaves field blank without username.The name appears to me on Textbox, but it does not appear in the table field or is added
So is the control bound to that field?
 

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
So is the control bound to that field?
Yes, when I put this event when loading the form and point to a text box that shows me the name of the user, but when I put the event on the Save changes button, it does not add the name of the user to the field in the table.
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:27
Joined
Sep 21, 2011
Messages
14,238
So cannot be bound then?
Why oh why do new people want to Save data all the time, when Access will do it for you? 😔
 

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
So cannot be bound then?
Why oh why do new people want to Save data all the time, when Access will do it for you? 😔
I know this, my friend. I know that Access saves data by simply leaving one field to another. I assume the name of this button is Save. Not only does it save the data, it transfers the name of the person who opened the database and manipulated or happened the data in it with a certain date to the table, knowing that once this data is changed, his name will do. Go to or update the history you tampered with. And that this employee knows that the database in his hands does this thing.
 

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
I know this, my friend. I know that Access saves data by simply leaving one field to another. I assume the name of this button is Save. Not only does it save the data, it transfers the name of the person who opened the database and manipulated or happened the data in it with a certain date to the table, knowing that once this data is changed, his name will do. Go to or update the history you tampered with. And that this employee knows that the database in his hands does this thing. ...... The employee when he knows that the database in his hands does this thing. It is impossible to give his password to another employee. Because he knows that his name will appear in one of the records whose data has been updated and not the name of his friend
 

June7

AWF VIP
Local time
Yesterday, 17:27
Joined
Mar 9, 2014
Messages
5,466
Perhaps it is time to provide db for analysis. Follow instructions at bottom of my post.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:27
Joined
Feb 19, 2002
Messages
43,233
Do you see the space between the r and the . Value?

Just FYI the .Value property is the default value for controls and therefore is optional so most people omit it Me.txtuser is sufficient

But, there is another problem that will bite you when you're not looking. The instructions are in the WRONG event. They belong in the FORM's BeforeUpdate event. That way, no matter what caused the record to be saved, Access ALWAYS runs the form's BeforeUpdate event as the LAST event before a record gets saved. It cannot be bypassed. It is also the event in which your form validation belongs for exactly the same reason. Think of this event a the flapper at the bottom of a funnel. The record MUST pass through the bottom of the funnel in order to be saved and your validation code can stop that from happening. When you put your validation code in the wrong events, you get a lot of nice messages but more than likely, the bad record just gets saved anyway because you are not able to stop it.

And finally, please, for everyone's sake, especially yours, give your controls meaningful names BEFORE you add code to them. or reference them in other code. I would suggest changing them now but it will be a PITA because changing the name of a control separates it from any existing event code so you have to find that code -- Private sub Command173_Click() for example and change Command173 to MyNiceName every place it is referenced in the form's module. Then you have to go back to the form and look at the Event properties of the control to make sure they reconnected. if there should be event code but you see nothing just click on the ellipsis and that will make the connection assuming you typed the new control name correctly.
 
Last edited:

azhar2006

Registered User.
Local time
Yesterday, 18:27
Joined
Feb 8, 2012
Messages
202
Good morning, friends
Thanks to all . The job worked well, and the reason for stopping it was two things. The first is the error that our colleague Gasman pointed out about (ou have a space before .Value, so Access does not see it as a property of txtUser) and the other reason is that the function does not work when I open the database in the design or the Shift button. 🌺 :):geek:
 

Users who are viewing this thread

Top Bottom