Put User name in form field

treva26

Registered User.
Local time
Today, 05:11
Joined
Sep 19, 2007
Messages
113
I have a database where everyone has to log in.

When they fill out a particular form, I want to automatically record thier username in one of the fields.

Is that possible?
 
If you are using Access security, you can get the userId from CurrentUser()

Me.UpdatedBy = CurrentUser()

If you are using security that you created yourself, hide the log in form rather than closing it and you will always be able to refer to the user name on that form.

Me.UpdatedBy = Forms!frmLogIn!UserID
 
Yes I am using Access security and it worked beautifully in my form thank you! :)

I dont suppose I can use that as a default vlaue in a table can I?
When I tried it it said "Unknown Function"
Could I write a function the default value can call that will return that value?
 
Yes I am using Access security and it worked beautifully in my form thank you! :)

I dont suppose I can use that as a default vlaue in a table can I?
When I tried it it said "Unknown Function"
Could I write a function the default value can call that will return that value?

When you put it into the default property did you use:

=CurrentUser()

with the parentheses and equals sign?
 
Yea I tried it with and without the equals sign, always with the parentheses.
 
Actually, it worked for me without the equals sign.

CurrentUser()

The thing to remember is that the default will ONLY work for NEW records. Existing records will not change.
 
It wont let me close the table, just says
" Unknown function 'CurrentUser' in validation expression or default value on 'Quotes.Entered ECL' "

Can I alter the table with SQL (I tried to but cant find the correct syntax)
Or make a new function that will be known that just puts the value in there?

Maybe its because Im using Access 2003?
 
It wont let me close the table, just says "Unknown Function in default value"

Can I alter the table with SQL (I tried to but cant find the correct syntax)
Or make a new function that will be known that just puts the value in there?

Maybe its because Im using Access 2003?

No, it is fine for me in Access 2003. Can you post your db? I'd like to see exactly what is going on. I think we just may not be connecting in some way.
 
ok well heres the table, the whole db is a bit big
 

Attachments

There are only a few functions you can use at the table level and I don't think that currentUser() is one of them - at least I've never gotten it to work.
 
Well, with Pat and Bob in here I don't know if I can add anything to this.... But here is something I use to record a users name.... On this I wanted to know who the user was when a report came to me..... so a function.....
Code:
Function GetUserName()
GetUserName = Environ("UserName")
End Function

Then I might have a field on a form.... eg.. "txtUserName"
and call the function

Code:
Private Sub Form_Open(Cancel As Integer)
Call GetUserName
txtUserName = GetUserName
End Sub

See if that might be what your looking for.
 
Well, with Pat and Bob in here I don't know if I can add anything to this.... But here is something I use to record a users name.... On this I wanted to know who the user was when a report came to me..... so a function.....
Code:
Function GetUserName()
GetUserName = Environ("UserName")
End Function

Then I might have a field on a form.... eg.. "txtUserName"
and call the function

Code:
Private Sub Form_Open(Cancel As Integer)
Call GetUserName
txtUserName = GetUserName
End Sub

See if that might be what your looking for.

Curtis:

The CurrentUser function works inside of forms too, but we were trying to see if we could get something to work inside the table's default and apparently only certain functions will work at table level for it.

The Environ code will not get the user name being used for Access security which is another reason why we were heading down the route we chose. But, if Access security isn't being used then the Environ code will work unless the user has changed their environment variables (most don't know how, that's for sure).
 
OK, good info Bob..... I have not used "Access security". Most of what I read doesn't regard it too highly, and the majority of my db's are for networks. So I leave the security up to the network level and user groups...
From what I have read I don't think too many are saying good things about Access security in 2007......But maybe some improvements have been made.
 
From what I have read I don't think too many are saying good things about Access security in 2007......But maybe some improvements have been made.
Actually, if you use the new ACCDB format, Access Security is no longer available in Access 2007. The only way you can use Access Security in Access 2007 is to stick with the older MDB format.
 
Good to know..... I haven't been doing too much developing in 07 yet. I usually jump back and forth 03 to 07 to try to make sure my apps works in both. This method has had it's downfalls! ie.... If you try to format any fields in 03 after designing the db in 07 it corrupts the form or report... has happened to me several times!
But that brings up a question.... maybe this should be a new post but... On security...All of my apps I design in split db's. The question is.... is my thinking on using server security correct? Can you simply create a group... like "AccessUsers" then place the backend in a file and have that file require the user to belong to "AccessUsers" group. Would this stop the db from functioning if the user did not belong to this group?
 
Can you simply create a group... like "AccessUsers" then place the backend in a file and have that file require the user to belong to "AccessUsers" group. Would this stop the db from functioning if the user did not belong to this group?
Yes, anyone who didn't belong to the appropriate A.D. group would not have rights to the folder and therefore it would generate an error in the frontend when they tried to open it.
 
Great... Thanks for the info Bob. I was hoping my thinking was on the right track.
 
Access causes network admins fits. Because of the way Jet works, EVERY Access application is technically secured. The security is silent though since the default login user is Admin who by default has all privledges. When a database is opened, Jet creates a lock file in the same directory as the .mdb or .mde with the same namb but the extension of .ldb. This means that ALL users must be given rights that allow them to create files in the database's directory. Issue two is when the last user closes the application, Jet deletes the .ldb file since it is no longer necessary. This means that ALL users must be given rights that allow them to delete files in the database's directory.

You can see the security implications of those permissions - they also allow the users to DELETE the front end and back end databases themselves!!

If you have cooperative network admins, you can get them to remove delete permissions from the specific .mdb or .mde files. This creates a management nightmare if they don't do it in an organized manner so most simply refuse to do it. For that reason, I have a strong preference for using something other than Jet as the back end database in a shared database environment. It is extremely easy for a fat-fingered user to simply blow away your database.
 

Users who are viewing this thread

Back
Top Bottom