CurrentUser function doesn't exist?

T

T. W.

Hello all,
I'm having a slight problem. I've applied Access security to an MDB
file (using the workgroup file), and it works fine.
I did this to track which user adds a record to certain tables. I have
two other fields in the same table with a default value of Time() and Date()
which both give the current time and date of the record being created or
updated. I added the third field with a default value of CurrentUser() but
it gives the below error message.

Unknown function 'CurrentUser' in validation expression or default value on
(gives the table.field name).

Does anyone know what's going on? The database is in Access 2000 file
format and I'm using Access 2003.
 
T

T. W.

Let me add that I'm not doing any of this in VBA. The Time() and Date()
functions are typed directly into the Default Value property fields of each
field in the table. CurrentUser() just gets the below error when saving.
 
L

Lynn Trapp

You cannot use the CurrentUser function in a table level default value.
Create a data entry form that is bound to your table. Set the default value
of the field in your table that will be storing the name of the user to
CurrentUser.
 
J

Joan Wild

In addition to Lynn's advice, you could have just a single field for the
date/time of update. Set the default value to Now() to get both date and
time.
 
T

Todd Shillam

T. W. said:
Hello all,
I'm having a slight problem. I've applied Access security to an
MDB file (using the workgroup file), and it works fine.
I did this to track which user adds a record to certain tables. I
have two other fields in the same table with a default value of
Time() and Date() which both give the current time and date of the
record being created or updated. I added the third field with a
default value of CurrentUser() but it gives the below error message.

Unknown function 'CurrentUser' in validation expression or default
value on (gives the table.field name).

Does anyone know what's going on? The database is in Access 2000 file
format and I'm using Access 2003.

If you just want to capture the user name into a table for whomever is
logged onto a Windows computer, just set the default value for the table's
field value to the %USERNAME% environmental variable. Here's what the
default would look like:

=Environ$("UserName")

Simple and it works. NOTE: You can use this same code in event procedures on
forms--I use both the environmental username and computername variables to
authenticate access on program splashscreens using the OnLoad event.

Dim vUserName As String
Dim vComputerName As String

vUserName = Environ$("UserName")
vComputerName = Environ$("ComputerName")

If vUserName <> "MyName" Then
MsgBox "You Are Not Authorized."
DoCmd.Quit
Else
'CONTINUE
End If

Best regards,

Todd
 
T

T. W.

We switched from Now() to seperate field containg Date() and Time() so as to
get more granular reports of the work being done, but I appreciate the
assist.
 
T

T. W.

I'm a little confused.

1) You're giving me info to put right into the field of the table, but below
that you say to right code for an event procedure. Do I have to write the
code or can I just put something in the Default Value property field?

2) You also say I can just put %USERNAME% (which I used in system admin
tasks) into the field, but below that you give =Environ$("UserName"), which
produces an error. So I also tried =Environ$(%USERNAME%) which still
produces the Environ% is an unkown function error.

I'm not versed enough with the VBA workspace to produce functions or methods
in there, so I'm hoping for an easier answer.

My primary goal is to track the user inputting the record. I would love to
be able to track by the username (since we will soon be moving to Access
front end with an SQL backend).
 
T

Todd Shillam

You can just insert the code:

=Environ$("UserName")

into the table's field Default Value property--should work just fine.

Todd
 
D

Douglas J. Steele

Check your references. With any code module open, select Tools | References
from the menu bar. Examine all of the selected references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by doing a Compile All Modules), go back in
and reselect them.

If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected. (NOTE: write down what the references are before you delete
them, because they'll be in a different order when you go back in)

For far more than you could ever want to know about this problem, check out
http://members.rogers.com/douglas.j.steele/AccessReferenceErrors.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top