Capture Users that Create and Edit the records

mikejaytlabustro

Access Database 2007 PH
Local time
Tomorrow, 05:37
Joined
Feb 11, 2013
Messages
93
What is the best way to capture the users that modify the records in the database?

Let us start from User Log-in Form
After log-in, Main Form will open
The main form has various menu (example Add Customer)
Once I open the "Add Customer Form", I want to record the username in the Createdby/Editedby Field automatically.
 
There are a number of ways this can be done. The easiest is to have a module with the following (have assumed this is numeric, but could be text:

Code:
Public pubUserID as Long
 
Public Function GetUserID() as Long
    GetUserID=pubUserID
End Function

Then in your login form, assign pubUserID with the ID of your user

In your beforeupdate event on the form use the following:

Code:
Me.UserID=pubUserID
or if you are using an insert or update query

Code:
Update myTable SET myTable.UserID=GetUserID()
Note you cannot access a public variable directly in SQL, hence the use of the function
 
sorry for jumping in, but I just thought I'd say: I just use

me.LastEditedBy=currentuser()

on the beforeupdate of my forms... and that seems to work ok, without using a separate function... don't know if there are any problems with this approach?
 
pubUserID=Me.UserID
I would expect to see this in your login form assuming me.userid is a valid field relating to the user logging in.

Me.UserID=pubUserID
This appears in the form you are using to edit data
 
CazB

The problem with currentuser is if you haven't established a security-enabled workgroup, the CurrentUser method returns the name of the default user account, Admin. The Admin user account gives the user full permissions to all database objects. - See this link http://msdn.microsoft.com/en-us/library/office/ff845778.aspx

You can only establish a security enabled workgroup in Access 2003 and earlier
 

Users who are viewing this thread

Back
Top Bottom