Username to be recorded in table

G

Guest

Dear friends, need help again :(

I can use the User-Level Security Wizard to protect my database (define
users, permissions etc). My question is:
Can I use the information entered on start-up screen (i.e. username and
password), so each new record or modified ones automatically record that
username on the related record?
I know how to do that with a custom form (using a table of users and
passwords), but can I do the same using the security feaures of MS-Access?
Thank you in advance,
George
 
A

Allen Browne

Just use CurrentUser() to retrieve the name of the current user.

Use the BeforeUpdate event of your form to assign that to a field, to record
who modified the record last.
 
M

m.cringle

Just use CurrentUser() to retrieve the name of the current user.

Use the BeforeUpdate event of your form to assign that to a field, to record
who modified the record last.

Hi Allen

I was just about to ask a very similar question ...

I would like to automatically record the author of each record and also
the last person to modify. How would i go about this? (If not possible,
just last modified would do)

I would expect to create 2 new text fields in the relevant table/s,
then in the form create a text box with CurrentUser() control source -
I'm not quite sure where to go from here tho?

What would I need to use in the BeforeUpdate event to append this data
to the table?

Thanks for your help!
 
A

Allen Browne

For the creator, you can just add:
=CurrentUser()
to the Default Value property of that field.

For the person who modifed the field:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not Me.NewRecord Then
Me.[NameOfYourFieldHere] = CurrentUser()
End If
End Sub

If you are not using Access security, you can record the name of the Windows
user. There's an example of that here:
http://allenbrowne.com/ser-53code.html#GetNetworkUserName
 
M

m.cringle

Allen said:
For the creator, you can just add:
=CurrentUser()
to the Default Value property of that field.

Sorry - me again!

I just tried inserting "=CurrentUser()" into the Default Value
property in my table but I get an error saying invalid property - any
ideas what I could be doing wrong?

I created a new field and in design view, inserted the above function
into the default value field. When I clicked the build button the
function did not appear in the available list.
 
A

Allen Browne

Try putting the expression into the Default Value of the text box on your
form, instead of the Default Value of the field in your table.

If necessary, you can write that in Form_BeforeUpdate as well:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
Me.[MyCreatedField = CurrentUser()
Else
Me.[MyModifiedField] = CurrentUser()
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top