Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use Windows login name as a variable in Approach

Status
Not open for further replies.

fruitcake

Technical User
Feb 23, 2002
5
GB
Hi, I am finishing off an application which would be greatly enhanced if I could use the users windows login name to enter into records.
For instance. I have several databases in my application and would like to monitor activity. I would like to know who changed the data last and who entered it in the first place. I have this already working using a login name when Approach starts up. A variable is then set and passed on to each datafile as it is created and altered.
It would be so much better if I could grab the users Windows login.
Does any one know if this is possible ?

Rob Price
 
You need to use LotusScript to call an API function to get the logon name and assign it to a variable field. Then you can add text fields to the table for CreatedBy and ModifiedBy with default creation and modification formulas (in Field Definition) pointing to the variable field:

Say you name the variable field vUser. Put it on the opening form and edit its object name to fbxUser. Create a global sub to make it invisible; in the script editor, press F5 to run it:
Code:
Sub sHideCtl
  CurrentView.Body.fbxUser.Visible = False
End Sub

'{Globals - Declarations}
Declare Public Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (Byval lpBuffer As String, _
nSize As Long) As Long
'_____________________________
'{Globals Initialize}
Sub Initialize

 Dim lngRtn As Long
 Dim strUserName As String * 255
 Dim lngNameLen As Long

 'Switch to the opening view
 Set CurrentApplication.ActiveView = CurrentDocument.NameOfView
 'Get the windows user name
 lngNameLen = 255
 lngRtn = GetUserName(strUserName, lngNameLen)
 'Assign it to the variable field
 CurrentView.Body.fbxUser.Text = _
 Left$(strUserName, lngNameLen - 1)

End Sub
If running Approach 9.0 or later, you also need to put a single comment character (') in the OpenWindow event of the DocumentWindow object to work around a bug in Initialize.

Paul Bent
Northwind IT Systems
 
Many thanks Paul, I am most thankfull.
Havn't tried it yet but I am sure it will be just what I need.
rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top