+ -
当前位置:首页 → 问答吧 → ACCESS中如何记录当前windows账号

ACCESS中如何记录当前windows账号

时间:2011-03-22

来源:互联网

access 新增一条记录能自动记录当前windows账号(AD 用户)。例如:产品表如下:
产品编号 产品名称  录入人员  录入日前

在窗体每增加一条记录到表中,录入日期自动获取当前系统日期,录入人员 也增自动获取当天登录电脑的域账号,这个应该怎么实现呢?

作者: Irma   发布时间: 2011-03-22

参考access帮助里面的GetLogonName函数

本主题包含用户定义的函数 GetLogonName,该函数用于返回当前用户名。GetLogonName 函数利用 GetUserNameA Windows API 来检索当前用户名。

' Access the GetUserNameA function in advapi32.dll and
' call the function GetUserName.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
     (ByVal lpBuffer As String, nSize As Long) As Long

' Main routine to retrieve user name.
Function GetLogonName() As String

    ' Dimension variables
    Dim lpBuff As String * 255
    Dim ret As Long

    ' Get the user name minus any trailing spaces found in the name.
    ret = GetUserName(lpBuff, 255)
     
    If ret > 0 Then
        GetLogonName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
    Else
        GetLogonName = vbNullString
    End If
End Function

作者: Gemmy   发布时间: 2011-03-22

谢谢!

作者: Irma   发布时间: 2011-03-22