autofill values for logged in users (1 Viewer)

matt.w.stevens

New member
Local time
Today, 05:52
Joined
Jul 19, 2019
Messages
5
Hello. I have created a database for a minimum of ten users to log into simultaneously and add records via a form. All of the records need to have the respective usernames appended to the records to show they were the ones entering the data.

How do I get access to do this? Do I really need to make a list of users and have them select themselves from a dropdown? Is there a way to get the form to display the user who is currently logged in?

Thanks in advance.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:52
Joined
Aug 30, 2003
Messages
36,123
Logged into Windows? Try Environ("username").
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:52
Joined
May 7, 2009
Messages
19,229
you need to Split the db (Fe-Be).
the front-end is given to each users.
then you can use:

environ("UserName")

to show the name of the user.
add the field, where the username will be save, to the form.
then make the Visible Property of the textbox to No.
also you add code to the BeforeUpdate event of your form, to add the UserName.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me![textBoxForUserName] = Environ("UserName")
End Sub
 

matt.w.stevens

New member
Local time
Today, 05:52
Joined
Jul 19, 2019
Messages
5
Putting that as a default value in the table's field's Default Value parameter returns an error message. "Unknown function 'Environ' in validation expression or default value on (field name)"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:52
Joined
May 7, 2009
Messages
19,229
don't put it on Default value, coz it's not on the list of built-in function.
use the Form's BeforeUpdate event.
 

matt.w.stevens

New member
Local time
Today, 05:52
Joined
Jul 19, 2019
Messages
5
don't put it on Default value, coz it's not on the list of built-in function.
use the Form's BeforeUpdate event.

Okay. I am using Access 2016 if that makes any difference. I've split the DB as well.

Entering


Private Sub Form_BeforeUpdate(Cancel As Integer)
Me![techid] = Environ("UserName")
End Sub

into before update gives me an invalid syntax error.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:52
Joined
Aug 30, 2003
Messages
36,123
I just tested this and it worked fine. I used the name of a textbox bound to a field in the table:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  Me.Text16 = Environ("username")
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:52
Joined
May 7, 2009
Messages
19,229
what datatype is TechID, string or numeric.
is it on the form?
 

matt.w.stevens

New member
Local time
Today, 05:52
Joined
Jul 19, 2019
Messages
5
I just tested this and it worked fine. I used the name of a textbox bound to a field in the table:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  Me.Text16 = Environ("username")
End Sub

Am I supposed to be entering this in the field's expression builder? It gives me three choices. Expression, code, and macro.
 

matt.w.stevens

New member
Local time
Today, 05:52
Joined
Jul 19, 2019
Messages
5
what datatype is TechID, string or numeric.
is it on the form?

techid is all lowercase. It's a short text data type. Display Control is Text Box.

It appears on the form as a blank text box when not in design mode.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:52
Joined
May 7, 2009
Messages
19,229
on design view of your form, on its Property Sheet->Event->Before Update.
you choose code from the selection.
 

Users who are viewing this thread

Top Bottom