On Monday, December 07, 2009 6:24 PM KenSheridan via AccessMonster.com wrote:
However you obtain the user name, and the API call suggested by Daniel is the
obvious solution, you should also create a Users table with UserName as its
primary key if you do not already have one, and create an enforced
relationship between it and the 'calls' table. That way the integrity of the
data is protected. Even if automating the insertion of a value into the
UserName column there would otherwise be nothing to prevent a value being
subsequently changed to that of a non-existent user. This might sound
unlikely, but Murphy's Law states not.
If you should decide not to use the unique login names, but employees' real
names then, as names can legitimately be duplicated and therefore are
unsuitable as keys, the Users table should have a numeric UserID as its key,
FirstName and LastName columns and a UserName column which corresponds to the
login name, along with other columns which identify the user such as their
job title etc., i.e. it would be more of a general Employees table. This
then caters for having two users of the same name (I worked once with two
Maggie Taylors). The calls table should then have a numeric UserID column as
a foreign key referencing the key of Users.
You can then put the following code in the calls form's Open event procedure
to set the DefaultValue property of its UserID control, which you would make a
hidden one as there is no point showing the arbitrary numeric value:
Dim strCriteria As String
strCriteria = "UserName = """ & fOSUserName() & """"
Me.UserID.DefaultValue = """" & DLookup("UserID", "Users", strCriteria) &
""""
You could then show the user name in the form in a control, either an unbound
one with a ControlSource:
=DLookup("(Firstname + "" "") & LastName", "Users", "UserID= " & [UserID)
or in a bound control if you base the form on a query which joins the calls
table to the users table. If doing the latter set the control's Enabled
property to False (No) and its Locked property to True (Yes).
Ken Sheridan
Stafford, England
wishfulthinking wrote: