Password Login - Auto Populate Fields

  • Thread starter Richard Perry via AccessMonster.com
  • Start date
R

Richard Perry via AccessMonster.com

Hi

I have a table of Users (5 users only) with passwords that I have given them
to log in to Access. This is not high security, just data entry. They want
to keep track of how many entries a user made during a day, week, month.

When the user type their password to the data entry form, their name, date
and time to auto populate the fields, which are protected and cannot be
changed.

My problem is that it works for the first record only. When they click on
"add a new record", the next data entry record does not have their name and
date stamp.
 
G

Graham Mandeno

Hi Richard

You should be using the DefaultValue property of those textboxes to provide
a default value for new records.

For the date/time field, just set the DefaultValue of the textbox to:
=Now()

For the username field, I suggest you use a global variable and a function
to return it. Put the following in a standard module:

Public gsCurrentUser as String

Public Function GetCurrentUser() as String
GetCurrentUser = gsCurrentUser
End Function

Now, change your login form which asks for the username and password so that
it stores the validated username in your public variable:
gsCurrentUser = Me!txtUserName

And, getting back to your data entry form, set the DefaultValue us the
username textbox to:
=GetCurrentUser()

You could also get clever and modify your GetCurrentUser function to check
if gsCurrentUser is an empty string and, if so, open up your login form to
ask for the username and password.
 
Top