Getting User Name (mdb 2007-2016 database) (1 Viewer)

juancarlos

Registered User.
Local time
Today, 13:37
Joined
Jan 29, 2019
Messages
18
Hello!

Currently, in the database I'm working on, there is a field in the Cases table to document the initials of the person handling a case.
|Policy | Client | Initials | Date Open |Category| Date Closed |Etc.|

When a case needs to be opened, they open a form, enter the pertinent information and either enter their own initials if they will be handling the case or leave it blank for a manager to assign later.

I've been asked to include a way to record who opens a case because they're leaving information out and we have no way of knowing how to track the information.

My idea is to add another field to the table |CUser| and, when they open the form to create a case, their name or initials populates, much like "Date()".

How would I implement that on a form? I remember trying "CurrentUser()" last year but that gave me "Admin" for everyone.

I could simply add a required field for them to enter their initials, but that's tedious and too easy to manipulate and make mistakes on.

Happy Friday!

-JC
 

juancarlos

Registered User.
Local time
Today, 13:37
Joined
Jan 29, 2019
Messages
18
Huh. That simple? Would that go in the default property for the field? If I do that I get a #Name? error.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:37
Joined
Oct 29, 2018
Messages
21,545
Hi. You could try it as a Default Value, but on a Form - not in a table.
 

juancarlos

Registered User.
Local time
Today, 13:37
Joined
Jan 29, 2019
Messages
18
Yeah, that's what I'm tying to do. I put it there and I get the error.
 

juancarlos

Registered User.
Local time
Today, 13:37
Joined
Jan 29, 2019
Messages
18
Awesome, thanks.

I open the form in Design View, select the field where I want the info and enter that snippet in "Default Value".
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:37
Joined
Oct 29, 2018
Messages
21,545
Awesome, thanks.

I open the form in Design View, select the field where I want the info and enter that snippet in "Default Value".
Which snippet? If you meant the Environ() one, did you precede it with an equals sign? A screenshot would be nice to help figure out the problem.
 

juancarlos

Registered User.
Local time
Today, 13:37
Joined
Jan 29, 2019
Messages
18
Yes. Just like this.

 

Attachments

  • CU.png
    CU.png
    9.1 KB · Views: 245

theDBguy

I’m here to help
Staff member
Local time
Today, 11:37
Joined
Oct 29, 2018
Messages
21,545
Hi. I guess that's not allowed. If so, try creating a function to return the result and use the function in the Default Value property.
 

Micron

AWF VIP
Local time
Today, 14:37
Joined
Oct 20, 2018
Messages
3,478
The form control is bound to a table field, yes? IIRC, can't use default value on unbound field. The approach being followed now would allow anyone to alter the default if control isn't hidden - is that OK? You should also be able to call any function (my preference is fosUserName ) as in = FunctionName()

I'd probably forget the control all together and write the value of the function to the table if the NewRecord property is true in the Current event. Going further, you could also use any function along with the appropriate event to capture who edited a record if that was of interest. As for Environ, I know a lot of people use it, and someone I know who was an Access expert once told me that some IT network change broke it and he had to go back into code in all db's and remove it. That's just an FYI for what it's worth to anyone.
 

isladogs

MVP / VIP
Local time
Today, 19:37
Joined
Jan 14, 2017
Messages
18,258
Just so the OP has got the full range of methods to choose from, I prefer the
WScript approach: http://www.mendipdatasystems.co.uk/get-user-name/4594424315 and also referenced in DBG's link

Environ can be 'spoofed' whereas WScript & fOSUserName cannot.
fOSUserName also works well but is more complex and requires API declarations for 32/64-bit
 
Last edited:

juancarlos

Registered User.
Local time
Today, 13:37
Joined
Jan 29, 2019
Messages
18
AHHHHH! IslaDogs: I see how that works. That form helped a lot.

Micron: yes, it is bound. We don't care much if they manipulate this value (I doubt they would know where to even start), we just want to be able to follow up.

TheDbGuy: I had gotten stuck creating the function, it gave me the compile error for 64-bit, but the example from IslaDogs is working.

Thank you so much!

-JC
 

isladogs

MVP / VIP
Local time
Today, 19:37
Joined
Jan 14, 2017
Messages
18,258
On behalf of all of us, you are welcome.
so in the end which did you use?
I assume fOSUserName as you mentioned 64-bit issues
 

juancarlos

Registered User.
Local time
Today, 13:37
Joined
Jan 29, 2019
Messages
18
Yes, fOSUserName is the one. I'm testing it on a copy of the database before I roll it out to the minions later tonight.
 

isladogs

MVP / VIP
Local time
Today, 19:37
Joined
Jan 14, 2017
Messages
18,258
I'm always intrigued why so many people use that when its so much more complex than the other methods!

Anyway, good luck feeding the minions
 

Users who are viewing this thread

Top Bottom