Gavin,
You can use the network's (or PC's) User Name for each person.
Let's say that you have a table called tblCustomers. Create a field in the
table
called UserName. Create a Main Menu (frmMainMenu), as well as TWO forms for
Customers: one for ADDING NEW Customers (frmCustomers_ADD) and a second for
EDITING EXISTING records called "frmCustomers_EDIT". (Make the RecordSource
for frmCustomers_ADD: "Select * from tblCustomers where false";
make the Record Source for frmCustomers_EDIT: "Select * from tblCustomers
where UserName = " & GetUser()
Now, create a text control on BOTH of these forms called UserName (just as
it is called in tblCustomers). Using the Properties for each of the UserName
controls, set Locked to Yes, set the ForeColor to 128, and the TabStop to
No. (This will prevent anyone from changing the data in UserName manually
via the forms.)
Now, in the frmCustomers_ADD form, use this code:
Private Sub Form_BeforeUpdate()
If IsNull(Me![UserName]) Or Me![UserName] = "" Then
Me![UserName] = GetUser()
Else
'do nothing
End If
End Sub
Next, in the frmCustomers_EDIT form, SKIP the above code, since the UserName
should already be in the table and thus on the form where it cannot be
altered.
====================================================
In the form frmCustomers_ADD AND frmCustomers_EDIT "General Declarations"
section, type:
Option Compare Database
Option Explicit
Private Declare Function GetUserName Lib "Advapi32.dll" Alias "GetUserNameA"
(ByVal sBuffer As String, nSize As Long) As Long
Private Function GetUser() As String
Dim sUserName As String
Dim lgSize As Long
Dim lgLength As Long
sUserName = String(15, " ")
lgSize = Len(sUserName)
lgLength = GetUserName(sUserName, lgSize)
GetUser = Left(sUserName, lgSize - 1)
End Function
=======================================================
The result: When you add a NEW customer, the Windows user name for the data
entry person will automatically be entered. In addition, when you open the
other form for editing/viewing, only you will be able to see the records you
entered.
There are many other ways to do this, but the use of the Windows/Network
User Name
is rather handy. I use it in many applications, where I save the:
DateCreated 'using Form_BeforeUpdate()
DateLastModified 'using Form_BeforeUpdate()
CreatedBy 'using the GetUser() function with Form_BeforeUpdate()
LastEditedBy 'using the GetUser() function with Form_BeforeUpdate()
---Phil Szlyk