Access Form History Field

psamu

Active Member
Joined
Jan 3, 2007
Messages
462
I am using a template. There are two field, one is "New Comment" and other one " History" Whenever user type in "New Comment" field , it appears in "History field" (For example I type in New Comment field "Test". It appears in History as "[Version: 9/14/2015 5:46:54 PM ] Test" . How do I change it to user name from desktop login name instead of Version: I see the formula is =ColumnHistory([RecordSource],"Comments","[ID]=" & Nz([ID],0)). Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I assume you do not already have the user login id as part of your db routine.
You can use the Environ("username") function (not sure of the syntax as I don't use it - it's buggy and can be spoofed). Or you can use a simple API call. This has to go in a standard module. The red part goes in the module's declaration section (at the top) and don't alter it. I can't make sense of the rest of your post, so I'm not sure where you should place & apiGetUserName(). Maybe where you have "[ID]"?:

Code:
[COLOR=#ff0000]Private Declare Function GetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long [/COLOR]

Function apiGetUserName() As String   'Call to apiGetUserName returns current user.   

Dim lngResponse As Long 
  Dim strUserName As String * 32 
  lngResponse = GetUserName(strUserName, 32) 
  apiGetUserName = Left(strUserName, InStr(strUserName, Chr$(0)) - 1) 
End Function

In case I mess up the code, it and other useful API calls are here:
10+ of my favorite Windows API functions to use in Office applications - TechRepublic
 
Upvote 0
I assume you do not already have the user login id as part of your db routine.
You can use the Environ("username") function (not sure of the syntax as I don't use it - it's buggy and can be spoofed). Or you can use a simple API call. This has to go in a standard module. The red part goes in the module's declaration section (at the top) and don't alter it. I can't make sense of the rest of your post, so I'm not sure where you should place & apiGetUserName(). Maybe where you have "[ID]"?:

Code:
[COLOR=#ff0000]Private Declare Function GetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long [/COLOR]

Function apiGetUserName() As String   'Call to apiGetUserName returns current user.   

Dim lngResponse As Long 
  Dim strUserName As String * 32 
  lngResponse = GetUserName(strUserName, 32) 
  apiGetUserName = Left(strUserName, InStr(strUserName, Chr$(0)) - 1) 
End Function

In case I mess up the code, it and other useful API calls are here:
10+ of my favorite Windows API functions to use in Office applications - TechRepublic

Thank you. I will try.
 
Upvote 0

Forum statistics

Threads
1,221,842
Messages
6,162,333
Members
451,759
Latest member
damav78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top