where do I put this VBA?

Geordie2008

Registered User.
Local time
Today, 23:18
Joined
Mar 25, 2008
Messages
177
Hi all,

I have a form which populates a table. When the form is used I would like to populate the table with the "username" of the person who po[pulated it.

Previously I used to use:

=Environ("UserName") in the default value of the table.

However, now that Im on XP from reading this forum I understand I need to use the following code:

'This function is used to allow the use of the Environ function in Access 2003



Public Function fGetUserName()
On Error GoTo Err_fGetUserName

fGetUserName = VBA.Environ("UserName")

Exit_fGetUserName:
Exit Function

Err_fGetUserName:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_fGetUserName

End Function



So far I have put this in the "Properties" ----> "Event" -----> "Before Update" and "After Update" as an "event procedure"

This returns the value "#Name?"

Im sure the code is fine and that I am just putting it in the wrong place...

Could someone please advise?

I would like the form to display the username and also populate it in a field in the database (called "RecordUser") when any changes are made to the values within the form.

Regards
Mandy
 
i thought environ still worked - try access help

=Environ("UserName") in the default value of the table.

if it doesnt work, i think this will only not work as the default value in the field. It will still work fine in vba code - therefore on the form you using to add new records, put a textbox (invisible0 if you like on the form, bound to the "recordcreator" field, and then in the

form beforeupdate event just put

Code:
if me.newrecord then recordcreator {the name of the textbox} = environ("username")


1) before update is called immediately before saving the record, so this is the palcefor it
2)test for newrecord first, or you will overwrite the value for existing records when you edit them
 

Users who are viewing this thread

Back
Top Bottom