How to show username automaticaly when a new record is created?

cos

Registered User.
Local time
Today, 22:48
Joined
Jul 13, 2012
Messages
81
I have a task whre the username of Access is to appear automatically in the Author Field, so that later, when re-viewing data, I can easily tell who entered a spesific record, as the file is on the shared drive.

I know that there's some easy way of doing it in excell where a macro can be recorded, but no clue on how to do it in Access :banghead:... any ideas at all?
 
thanks!!
but how do I save that into the table? =/
 
In the Form's On Current event you could use some code along the lines of;

Code:
If  Me.NewRecord Then
     Me.YourUserFieldName = CurrentUser()
End If
 
where exactly do I paste this code in to? on the form, do I click "view code" and copy it there?
 
You will need to put it into the Form's On Current event using an Event Procedure

attachment.php


You will need to change the red highlighted portions of the code to match the reality of your DB.
Code:
If  Me.NewRecord Then
     Me.[B][COLOR="Red"]YourUserFieldName[/COLOR][/B] = CurrentUser()
End If
 

Attachments

  • Image.jpg
    Image.jpg
    24.7 KB · Views: 289
I did as you said, and ths is the error message i get..
p.s. i don't think it likes it...:(

and when i ange it around a little bit, it says that the "Me." is an "Invalid outside procedure"..
 

Attachments

  • error message.png
    error message.png
    49 KB · Views: 118
  • error 2.png
    error 2.png
    52.4 KB · Views: 123
Last edited:
That code works as advertised in my Sanbbox DB :confused:

Did you copy and paste it into the Visual Basic code window and make the required adjustments. To get to the Code window you need to click on the Ellipsis button at the right hand side of the On Current [Event Procedure].
 
The code provided goes between the Sub Form_Current() and End Sub code stubs.
 
In which case i receve another error, and then when i click OK, the "Private Sub Form_Current()" is highlited in yellow.. any ideas on how i can fix this?
 

Attachments

  • error 3.png
    error 3.png
    40.3 KB · Views: 111
Please see my comments in Post #6, in which I advised that you would need to change that portion of the code to reflect the reality of your DB
 
it seem to work now!! Thank you ever so much! :D

however i do have another minor issue which i will post seporatly =/
 

Users who are viewing this thread

Back
Top Bottom