Adding the user's name to a table

J

June

Hi
I can capture the user that is logged into my database. I would like to take that information and update the table with this person. I have already figured out how to get the current date/time. Now I just need to know how to get the person in there. Why do I want to do this? I want to do this so I know who is accessing my database so if they compain that they don't have the information that they need then I can check to see if they have looked for the information in my database
Here's my code and my table is called tblUsers with a field called Users that I want to add to

Declare Function wu_GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Lon
Function ap_GetUserName() As Varian


Dim strUserName As Strin
Dim lngLength As Lon
Dim lngResult As Lon

'-- Set up the buffe
strUserName = String$(255, 0
lngLength = 25

'-- Make the cal
lngResult = wu_GetUserName(strUserName, lngLength

'-- Assign the valu
ap_GetUserName = strUserNam

' Put user name into the tblUser

Thanks June
 
D

Douglas J. Steele

Access doesn't allow you to use user-defined functions as default values in
tables. Your only option is to use a form for input: then, you can set the
default value of the textbox on the form to that function (or else set the
field's value in the form's BeforeUpdate event)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


June said:
Hi,
I can capture the user that is logged into my database. I would like to
take that information and update the table with this person. I have already
figured out how to get the current date/time. Now I just need to know how
to get the person in there. Why do I want to do this? I want to do this so
I know who is accessing my database so if they compain that they don't have
the information that they need then I can check to see if they have looked
for the information in my database.
 
P

pdm

If you are using user level security you can set a table field default value to the internal function CurrentUser(), the same way you can set the default of a datetime field to Now().
 

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