Create Login Form on Database Open (1 Viewer)

billgyrotech

Banned
Local time
Yesterday, 21:25
Joined
Apr 18, 2013
Messages
258
Hello,


How can I create a login form that will ask for Employee Name (combo box) and password field that once correct will have a different command button on my Switchboard as to what version of the AFRs form to open?


There are AFRs versions:


AFRs1 is Administrator
AFRs2 is Clerk
AFRs3 is Technician
AFRs4 is Research


I have in place an Employees table with foreign IDs from the SecurityLevels table to determine for each employee and also there are passwords.


I have not related these 2 new tables yet and not sure how to put this all together.


I appreciate any help or guidance,
Bill
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 02:25
Joined
Feb 19, 2013
Messages
16,553
1. include a quit button on your login form to exit the app if user cannot supply correct username and password

2. create a vba function along these lines in the password control afterupdate event (or have another button for the user to click after they have entered their details

Code:
private sub txtPassWord_afterUpdate()
dim userRoleID as long

if isnull(txtuserName) or isnull(txtpassWord) then
    msgbox "Please complete both fields"
    exit function
end if

userRoleID=nz(dlookup("RoleID","tblUsers","username='" & txtuserName & "' AND password='" & txtpassWord & "'"),0)
if userRoleID=0 then
    msgbox "incorrect username or password, please reenter"
else
    docmd.openform "frmSwitchboard",,,,,,userRoleID
    docmd.close "frmLogin"
end if

end sub

userRoleID is passed to the switchboard form as an openarg value so in your switchboard form open event you might have something like

Code:
Select Case OpenArgs
    Case 1
         btnA.visible=true
         btnB.visible=false
    Case 2
         btnA.visible=false
         btnB.visible=true
End Select
 

Users who are viewing this thread

Top Bottom