Name Association (1 Viewer)

ZetecS

Registered User.
Local time
Today, 23:40
Joined
Nov 30, 2009
Messages
21
Good morning all,

After some great, great help on this forum yesterday today I have another issue I would like some help with :).

I am just tweaking my database and I would like to add some validation.

I have a userID field which will currently allow the user to enter there name, but I would like it in a certain format.

Is there anyway in which I could code the form so that on form load the box would be populated with the name of the user that is currently logged on to the computer where the database has been opened from.

Many thanks,
 
As inserting the data in specific format look in the help for Mask
 
As inserting the data in specific format look in the help for Mask
I guess once ZetecS has retrieved the userID using the code provided, he won't be needing to apply an input mask because there will be no inputting.

But it's a good learning tip though ;)
 
Hi guys,

I have successfully managed to do this using the following code

Code:
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function

I have set the input mask on the text box to be =fOSUserName() and it has worked.

Thanks for your help.
 
What is the point of this? :confused:

TBH man I don't know I have just gone thru the steps that was on a website and it works for what I need it for. If the time comes where it doesn't work anymore for whatever reason then it would be time to change it but as now it does work.
 
Ok, the textbox can't be editted right? The value is gotten automatically from the function right?
 
Ok, the textbox can't be editted right? The value is gotten automatically from the function right?

Havent even tried to edit it if I am honest. Tho what I do have to say is when a record is created when a member of IT go in to edit the record to assign it too a member of the IT team the original username field doesn't get overwritten which I was glad about.
 
Well, you won't be able edit anyway.

There's no harm having the input mask set but I was just making sure you understood why you were doing it. The only time it will break is if the user id doesn't meet your Input mask criteria.
 
Well, you won't be able edit anyway.

There's no harm having the input mask set but I was just making sure you understood why you were doing it. The only time it will break is if the user id doesn't meet your Input mask criteria.

Ok man. Well thank you for your input.
 

Users who are viewing this thread

Back
Top Bottom