HELPPPP

M

mat

HI People, I have a question, it may be easy, i use the
below bit of code

Private Declare Function GetUserName Lib "advapi32.dll"
Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As
Long) As Long

To obtain peoples user names however i can't seem to get
it to track into tblsales.userid - could anybody send me
the code to get it to track this? i already have it
tracking other details - that are all user input - please
help
 
G

Graham Mandeno

Hi Mat

What you have posted is not a "bit of code", but an external function
declaration. By itself it does nothing and is useless. You need to write
your own function (say, WindowsUsername) which calls this function and
returns the result. Then you can, for example, set the DefaultValue of a
textbox bound to tblsales.userid to:
=WindowsUserName()

Oh OK... this is what your function needs to look like :)

Public Function WindowsUsername() As String
Dim sBuffer As String, lSize As Long
lSize = 256
sBuffer = Space$(lSize)
If GetUserName(sBuffer, lSize) Then
WindowsUsername = Left$(sBuffer, lSize - 1)
End If
End Function

Put it in the same module as your Private Declare line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top