开发者

Login module in Access

开发者 https://www.devze.com 2023-03-08 04:58 出处:网络
I\'m engaging in a log in module for my Access program. But I don\'t know much about it. The uses log in their computers with windows logins, and in the 开发者_JAVA技巧database I have a table describ

I'm engaging in a log in module for my Access program. But I don't know much about it.

The uses log in their computers with windows logins, and in the 开发者_JAVA技巧database I have a table describing every login and their roles(worker, manager etc.).

What I want to do is when my program starts, it can auto detect the windows login, and according to the table, decides to hide some forms or reports.

Any suggestions? Thanks ..


Try this. Enter this outside of a procedure:

Private Declare Function GetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

And enter this procedure:

Function GetUser() As String
    Dim cn As String, Userstr As String
    cn = String(1024, 0)
    If GetUserName(cn, 1024) <> 0 Then GetUser = Replace(cn, Chr(0), "")
End Function

Then GetUser() should give you the windows login name. I use this in several Access 2003 Frontends running on XP machines and haven't had any problems with it.

(Side note: I actually got this code from Stack Overflow a long time ago, but I have no idea who gave it to me, so I can't give proper credit)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号