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 don't 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'd 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
Post by wishfulthinkingI have a form set up to track what the calls we recieve are about. There are
15ish people that will be using the form and I was wondering if there is a
way to have the form auto fill the name of the user creating the new record,
the way it is set up to auto fill the date and time the new record is
created. This would prevent anyone from accidently clicking on the wrong
name if set it up as a list box. Please advise if this can be done and how.
--
Message posted via http://www.accessmonster.com