By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,742 Members | 2,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,742 IT Pros & Developers. It's quick & easy.

Writing GetUserName value to table

P: n/a
Hi all, I would like to take the function below and write the user name
to a field on a form and store it in the corresponding table but I'm not
sure how to get to where I'm at to where I need to be.

I'm doing this to track which user made what entry into the database:

Public Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Dim strCompName As String
Dim strUserName As String
Dim lLen As Long
Dim lNum As Long

strCompName = String(255, 0)
strUserName = String(255, 0)

lLen = GetComputerName(strCompName, Len(strCompName))
lNum = GetUserName(strUserName, Len(strUserName))
strCompName = Left$(strCompName, InStr(1, strCompName, Chr$(0)) - 1)
strUserName = Left$(strUserName, InStr(1, strUserName, Chr$(0)) - 1)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
One way is to bind the field to a text box on the form
(it can be invisible) and set the default value of the
control to "=GetName()"

Where GetName is a function you have defined which
includes your code and ends like:
GetName = strUserName
End Function
"casey a" <ca******@comcast.net> wrote in message
news:41**********************@news.newsgroups.ws.. .
Hi all, I would like to take the function below and write the user name
to a field on a form and store it in the corresponding table but I'm not
sure how to get to where I'm at to where I need to be.

I'm doing this to track which user made what entry into the database:

Public Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Dim strCompName As String
Dim strUserName As String
Dim lLen As Long
Dim lNum As Long

strCompName = String(255, 0)
strUserName = String(255, 0)

lLen = GetComputerName(strCompName, Len(strCompName))
lNum = GetUserName(strUserName, Len(strUserName))
strCompName = Left$(strCompName, InStr(1, strCompName, Chr$(0)) - 1)
strUserName = Left$(strUserName, InStr(1, strUserName, Chr$(0)) - 1)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #2

P: n/a


This seems to get me closer, only problem this seems to yield is that it
only wants to work if the field is unbound. I need it to be written to
the same table as the data. Thanks for the feedback.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

P: n/a
It works for me - you don't also have a default value
set for the bound field in the table do you?

You can also call the function from an update or
append query.

(david)
"casey a" <ca******@comcast.net> wrote in message
news:41**********************@news.newsgroups.ws.. .


This seems to get me closer, only problem this seems to yield is that it
only wants to work if the field is unbound. I need it to be written to
the same table as the data. Thanks for the feedback.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.