Login, password are common topics. Search forum or google.
For starters
https://www.accessforums.net/forms/u...gin-22943.html
http://forums.aspfree.com/microsoft-...7t-406737.html
I have a table 'Users' with fields:
UserNetworkID
UserInitials
ComputerName
I get the user name from network with
VBA.Environ("USERNAME") - yes, type it EXACTLY as shown.
Access will not recognize the Environ function but VBA will. Code from my db:
Code:
Option Compare Database
Option Explicit
Private Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long
Private Sub Form_Load()
Dim Shell
If Me.tbxVersion <> Me.lblVersion.Caption Then
If VBA.Environ("UserName") <> "MY USERNAME IS HERE" Then
'Because administrator opens the master development copy, only run this for non-administrator users
'Check for updates to the program on start up
'If values don't match then there is a later version
Set Shell = CreateObject("WScript.Shell")
Shell.Run CurrentProject.Path & "\Update.vbs"
Dim WAIT As Double
WAIT = Timer
While Timer < WAIT + 3
DoEvents
Wend
Set Shell = Nothing
Application.Quit
End If
Else
Me.tbxVersion.Visible = False
Call UserLogin
End If
End Sub
Private Sub tbxUser_AfterUpdate()
If Me.tbxUser Like "[A-Z][A-Z][A-Z]" Or Me.tbxUser Like "[A-Z][A-Z]" Then
CurrentDb.Execute "INSERT INTO Users(UserNetworkID, UserInitials) VALUES('" & VBA.Environ("UserName") & "', '" & UCase(Me.tbxUser) & "')"
Call UserLogin
Else
MsgBox "Not an appropriate entry.", vbApplicationModal, "EntryError"
End If
End Sub
Private Sub UserLogin()
Me.tbxUser = DLookup("UserInitials", "Users", "UserNetworkID='" & VBA.Environ("UserName") & "'")
If Not IsNull(Me.tbxUser) Then
'user in User table, continue to MainMenu
CurrentDb.Execute "UPDATE Users SET ComputerName='" & VBA.Environ("ComputerName") & "' WHERE UserInitials='" & Me.tbxUser & "'"
DoCmd.OpenForm "Menu", acNormal, , , , acWindowNormal, Me.tbxUser
DoCmd.Close acForm, Me.Name, acSaveNo
End If
End Sub