Login module in Access
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)
精彩评论