Situation: upgrading Access 2003 databases to Access 2013.
Required: Table with fields "CreatedBy" with default value of ' =Environ("UserName") '. Data entry is completed via form, not directly into table, LastMaintained and LastMaintainBy, each with no default value.
Function UserNameWindows() As String
username = Environ("USERNAME")
As soon as user begins to enter data, the default value for this field should populate with the username of the individual logged in (yes, I realize from others posts concerning altering via SET command, but company is less than 25 people and none know of such methods).
This has and always worked in Access 2003, but will not work in Access 2013.
Yet, form has an OnOpen Event with following code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.LastMaintained = Now()
Me.LastMaintainedBy = Environ("UserName")
These fields get the correct information no problem.
The error that occurs either when entering a new or updating an existing record.
"Unknown function "ENVIRON" in validation express or default value on "nameofform.nameoffield".
Help reflects error 3388 - The function you are referring to is either unknown (because the name is invalid) or misspelled or is a type of function not allowed by the validation rule or default value property. Among the types of functions not allowed are user-defined, SQL Aggregate function.
I tried removing default value from the field in the table with no change (still same error).
I cannot assign the ENVIRON= to the CreatedBy field because then every time the form is opened, it will overwrite that field (so the original creator will be overwritten with the last user who maintains the record).
Any ideas, I have some more databases with similar code that needs to be upgraded.
Thanks in advance.