473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Writing GetUserName value to table

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
3 3929
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: smj92I | last post by:
Hello How to get the name of the user logged in the server side, is there something like GetUserName? Thanks
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
7
by: Ajar | last post by:
I want to write a program which will automatically login to my ISPs website, retrieve data and do some processing. Can this be done? Can you point me to any example python programs which do similar...
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
4
by: Robert | last post by:
I am using VB.NET and need to get the user's name that has logged onto the user's computer. In VB6 I used an API call. Is this still the most efficint way or does the .NET framework have an...
8
by: OHM | last post by:
Hi peoples, I dont know where to place this question, so as I know you guys are all resourceful experts, I thought I would try here. I am writing some code which will be run usingh remote...
3
by: planetthoughtful | last post by:
Hi All, I'm building a Windows Form application that will use a Microsoft Access mdb file as a data store. I have a section of code that is executed when the main form is closed that _should_...
5
by: jlbess | last post by:
I'm using the following code in a C++ dll to retrieve the windows username of the current logged in user. I'm passing the username to a case sensitive application so I need to convert it to all lower...
5
by: venujune6 | last post by:
Hi, I have a tool which is made in C and uses the API GetUserName(). But we have the problem as the user says it gives incorrect username "sometimes". When the failure occurs, the username. that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.