Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Name to appear on a form 2

Status
Not open for further replies.

pmo

Technical User
Jan 15, 2001
76
AU
I am trying to have a field on a form that has a default value of the username of the person who is entering the data.
My database requires a user to log on. I have a form with a field that I want to default to the users name.

Can anyone help please.
 
not sure if you can use this but this is what i use.
if the user has to login to their computer this may help.

this is what i use to return the values

'Get UserName Function
UserName = ap_GetUserName()
CmpName = ap_GetComputerName()

Code:
Option Compare Text
Option Explicit

Declare Function wu_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
    (ByVal lbBuffer As String, nsize As Long) As Long
    
Declare Function wu_GetComputerName Lib "kernel32" Alias _
    "GetComputerNameA" (ByVal lpBuffer As String, nsize As Long) As Long
    
Public Function ap_GetUserName() As Variant

Dim strUserName                             As String
Dim lngLength                               As Long
Dim lngResult                               As Long

'-----  Set up the buffer
strUserName = String$(255, 0)
lngLength = 255
'-----  Make the call
lngResult = wu_GetUserName(strUserName, lngLength)

'-----  Assign the value
ap_GetUserName = strUserName

ap_GetUserName = Left(strUserName, InStr(1, strUserName, _
    Chr(0)) - 1)
    
End Function

Public Function ap_GetComputerName()

Dim strComputerName                         As String
Dim lngLength                               As Long
Dim lngResult                               As Long

'-----  Set up the buffer
strComputerName = String$(255, 0)
lngLength = 255

'-----  Make the call
lngResult = wu_GetComputerName(strComputerName, lngLength)

'-----  Clean up and assign the value
ap_GetComputerName = Left(strComputerName, InStr(1, strComputerName, _
    Chr(0)) - 1)
    
End Function
 
Thanks "thegameoflife".
My knowledge of code is almost nill so I had someone work through your email with me. Apparently your function will retrieve the computer logon user name. (Is that correct)??

The one I am chasing is the user that has logged onto the sucure access database. I had hoped that there would be some type of inbuilt function?

Any advice?

 
I will have an answer for you tomorrow (Thursday).

use the search function on this site and google.
 
thegameoflife,
Thanks for your help. I have success.
 
You can use the function: CurrentUser() to return the username as in the Access security as opposed to the windows login.

Dean. :)
 
Dean,
Thanks.
This is exactly what I have been chasing.

Wayne
 
I have a report that I want to analyze with Excel but it does not show in the menu bar,Can anybody tell me how to enable it.It shows in design mode but not when I run the Access Project
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top